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

新聞縮略圖模塊

original 2019-04-05 21:31:59 241
abstrait:<?php /**  * Created by PhpStorm.  * User: Admin  * Date: 2019/4/5  * Time: 20:03  */ namespace app\admin\controller; use
<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2019/4/5
 * Time: 20:03
 */

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()
    {
        //查詢數(shù)據(jù)
        $new_pic = NewsPicModel::all();
        $this->view->new=$new_pic;
        return $this->fetch();
    }
    //渲染添加頁面
    public function  add()
    {
        //查詢新聞title數(shù)據(jù)
        $new = NewsModel::all();
        $this->view->new=$new;
        return $this->fetch();
    }
    //圖片上傳
    public function upload()
    {
        //獲取圖片信息
        $pic = Request::file('file');
        //驗(yàn)證圖片并移到指定目錄下
        if($info = $pic->validate(['ext'=>'jpg,png,gif'])->move('smallImg')){
            //獲取圖片路勁
            return json([1,'上傳成功','data'=>'/smallImg/'.$info->getSaveName()]);
        }else{
            return $pic->getError();
        }
    }
    //添加縮略圖數(shù)據(jù)
    public function DoAdd()
    {
         //獲取前臺(tái)提交過來的數(shù)據(jù)
        $data = Request::param();
        $data['username']=Session::get('username');
        $data['time']=time();
        //判斷數(shù)據(jù)是否添加成功
        $news = new NewsPicModel();
        if($news->save($data)){
            return ['res'=>1,'msg'=>'添加成功!'];
        }else{
            return ['res'=>0,'msg'=>'添加失敗!'];
        }
    }
    //數(shù)據(jù)刪除
    public function del()
    {
        //獲取前臺(tái)提交的id
        $id = Request::param('id');
        $res = NewsPicModel::destroy($id);
        if($res){
            return ['res'=>0,'msg'=>'刪除成功!'];
        }else{
            return ['res'=>0,'msg'=>'刪除失??!'];
        }
    }
}


Professeur correcteur:西門大官人Temps de correction:2019-04-08 10:12:35
Résumé du professeur:數(shù)據(jù)的添加,盡量手動(dòng)賦值,這樣可以避免前臺(tái)傳過來非法的字段,造成數(shù)據(jù)庫報(bào)錯(cuò),泄漏數(shù)據(jù)庫信息

Notes de version

Entrées populaires