サマリー:<?php namespace app\admin\controller; use app\admin\controller\Common; use app\admin\model\NewsModel; use app\admin\model\NewsPicModel; use think\facade\Request; use
<?php namespace app\admin\controller; use app\admin\controller\Common; use app\admin\model\NewsModel; use app\admin\model\NewsPicModel; use think\facade\Request; use think\facade\Session; class NewsPic extends Common { public function index(){ //查詢操作 $newPic = new NewsPicModel(); $pics = $newPic->order('id','desc')->paginate(6); $this->view->pics = $pics; //渲染新聞縮略圖列表 return $this->fetch(); } public function add(){ //在下拉條中導(dǎo)入新聞數(shù)據(jù),將數(shù)據(jù)賦值給模板 $news = NewsModel::all(); $this->view->news=$news; //渲染新聞縮略圖的添加界面 return $this->fetch(); } //上傳縮略圖 public function upload(){ //獲取上傳圖片信息 $file = Request::file('file'); //validate完成自動(dòng)驗(yàn)證,后綴。驗(yàn)證并移動(dòng)到指定目錄upload if($info = $file->validate(['ext'=>'jpg,jpeg,png,gif'])->move('upload')){ //將圖片路徑進(jìn)行拼接 $fileName = '/upload/'.$info->getSaveName();//獲取圖片名稱 //返回上傳成功的提示信息 return json([1,'上傳成功!','data'=>$fileName]); }else{ //返回上傳失敗的錯(cuò)誤信息 return $file->getError(); } } public function DoAdd() { //獲取提交的數(shù)據(jù) $data = Request::param(); $data['time']=time(); $data['username']=Session::get('username'); //進(jìn)行存儲(chǔ)操作 $newPic = new NewsPicModel(); if($newPic->save($data)){ return ['res'=>1,'msg'=>'發(fā)布成功!']; }else{ return ['res'=>0,'msg'=>'發(fā)布失??!']; } } public function del(){ $picId=Request::param('id'); $newPic = new NewsPicModel(); if($newPic->destroy($picId)){ return['res'=>1,'msg'=>'已刪除']; }else{ return['res'=>0,'msg'=>'刪除失敗']; } } }
添削の先生:天蓬老師添削時(shí)間:2019-04-12 14:10:12
先生のまとめ:return['res'=>0,'msg'=>'刪除失敗']; return 與數(shù)組之間有空格嗎? 看不出來呀