KnowController.php 1.2 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/15
 * Time: 14:19
 */

namespace app\admin\controller;


use cmf\controller\AdminBaseController;
use think\Db;
use think\Validate;

class KnowController extends AdminBaseController
{
    public function index()
    {
        $id = $this->request->param('id', 1, 'intval');
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $validate = new Validate([
                'thumbnail' => 'require',
            ]);
            $validate->message([
                'thumbnail' => '缩略图不能为空',
            ]);
            if (!$validate->check($param)) {
                $this->error($validate->getError());
            }
            $param['update_time'] = time();
            Db::name('knowledge')
                ->where('id', $id)
                ->update($param);
            $this->success('更新成功');
        } else {
            $data = Db::name('knowledge')
                ->where('id', $id)
                ->find();
            $this->assign([
                'data' => $data,
            ]);
            return $this->fetch();
        }
    }
}