亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

新聞縮略圖模塊

Original 2019-03-29 17:02:08 206
abstract:class NewsPic extends Common{    public function index()    {        //實例化模型        $newPic = new NewsPicModel();        

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()
   {
       // 查詢所有新聞數(shù)據(jù)
       $news = NewsModel::all();
       //將數(shù)據(jù)賦值給模板
       $this->view->news = $news;
       // 渲染新聞縮略圖添加界面
       return $this->fetch();
   }

   public function upload()
   {
       // 獲取上傳圖片的信息
       $file = Request::file('file');
       // 驗證圖片并移動到指定目錄
       if ($info = $file->validate(['ext' => 'jpg,jpeg,png,gif'])->move('upload')) {
           // 拼接圖片路徑
           $fileName = '/upload/' . $info->getSaveName();
           // 返回上傳成功的提示信息
           return json([1, '上傳成功!', 'data' => $fileName]);
       } else {
           // 返回上傳失敗的錯誤信息
           return $file->getError();
       }

   }

   public function DoAdd()
   {
       // 獲取提交的數(shù)據(jù)
       $data = Request::param();
       $data['time'] = time();
       $data['username'] = Session::get('username');
       $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];
       }

Correcting teacher:天蓬老師Correction time:2019-03-30 10:24:03
Teacher's summary:對于控制器來說, 最常用的就是CURD, 其實框架還提供了命令的, 可以一條指令生成主要的CURD代碼,可以查閱手冊

Release Notes

Popular Entries