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

產(chǎn)品縮略圖-模塊

オリジナル 2019-03-02 10:12:33 184
サマリー:<?php/** * Created by PhpStorm. * User: Administrator * Date: 2019-02-19 * Time: 16:15 */namespace app\admin\controller;use app\admin\controller\Common;use app\admin\model\

<?php

/**

 * Created by PhpStorm.

 * User: Administrator

 * Date: 2019-02-19

 * Time: 16:15

 */


namespace app\admin\controller;

use app\admin\controller\Common;

use app\admin\model\ProductModel;

use app\admin\model\ProductPicModel;

use think\facade\Request;

use think\facade\Session;


class ProductPic extends Common

{

    public function index()

    {

        //查詢數(shù)據(jù)獲得列表

        $proPic = new ProductPicModel();


        $productPic = $proPic -> order('id','desc') -> paginate(4);


        //賦值模板變量

        $this->view->productPic = $productPic;


        //渲染模板

        return $this->fetch();

    }


    public function add()

    {

        //查詢所有產(chǎn)品數(shù)據(jù)

        $product = ProductModel::all();


        //將數(shù)據(jù)賦值給模板

        $this->view->product=$product;


        //渲染產(chǎn)品縮略圖添加界面

        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');


        //實例化產(chǎn)品縮略圖模型

        $proPic = new ProductPicModel();


        //存儲并驗證

        if($proPic->save($data)){

            //返回數(shù)據(jù)

            return ['res'=>1,'msg'=>'發(fā)布成功!'];

        }else {

            //返回數(shù)據(jù)

            return ['res'=>0,'msg'=>'發(fā)布失敗!'];

        }



    }


    public function del()

    {

        //獲取要刪除的產(chǎn)品id

        $productId = Request::param('id');

        //實例化模型

        $productPic = new ProductPicModel();


        //刪除并驗證

        if($productPic->destroy($productId)){

            return ['res'=>1,'msg'=>'刪除成功!'];

        }

    }



}


添削の先生:韋小寶添削時間:2019-03-02 13:26:15
先生のまとめ:整體的看并不是很復(fù)雜 實際上這里的上傳可以放到公共文件中 所有的上傳都公用一個

手記を発表する

人気のある見出し語