サマリー:<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/5/14 * Time: 13:03 */ namespace app\admin\control
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/5/14 * Time: 13:03 */ namespace app\admin\controller; use app\admin\controller\Common; use app\admin\model\SortModel; use think\facade\Request; use think\facade\Session; class Sort extends Common { public function index() { // 實(shí)例化模型 $sort = new SortModel(); // 查詢數(shù)據(jù)并按照id的順序 $sorts = $sort->order('id', 'desc')->paginate(2); // 蔣數(shù)據(jù)賦值給模板 $this->view->sorts = $sorts; // 渲染分類列表 return $this->fetch(); } public function DoAdd() { // 獲取提交過來的數(shù)據(jù) $data = Request::param(); // 獲取添加數(shù)據(jù) $data['time'] = time(); // 獲取發(fā)布管理員 $data['username'] = Session::get('username'); // 實(shí)例化模型 $sort = new SortModel(); // 存儲并驗(yàn)證 if ($sort->save($data)) { // 返回對應(yīng)信息 return ['res' => 1, 'msg' => '添加成功!']; } else { return ['res' => 0, 'msg' => '添加失敗!']; } } public function edit() { // 獲取需要修改的分類id $sortId = Request::param('id'); // 使用分類的id查詢對應(yīng)的數(shù)據(jù) $sort = SortModel::get($sortId); // 將數(shù)據(jù)賦值給模板 $this->view->sort = $sort; // 渲染修改界面 return $this->fetch(); } public function DoEdit() { // 獲取提交數(shù)據(jù) $data = Request::param(); // 實(shí)例化模型 $sort = new SortModel(); // 修改更新操作 $info = $sort->save([ 'sortname' => $data['sortname'], 'time' => time(), 'username' => Session::get('username'), ], ['id' => $data['id']]); // 驗(yàn)證修改結(jié)果 if ($info) { // 返回對應(yīng)值 return ['res' => 1, 'msg' => '修改成功!']; } else { return ['res' => 0, 'msg' => '修改失?。?#39;]; } } public function del() { // 獲取需要刪除的分類id $sortId = Request::param('id'); // 實(shí)例化模型 $sort = new SortModel(); // 刪除并驗(yàn)證 if ($sort->destroy($sortId)) { return ['res'=>1,'msg'=>'刪除成功!']; } } }
添削の先生:查無此人添削時(shí)間:2019-05-15 14:00:39
先生のまとめ:完成的不錯,后臺cms管理系統(tǒng),大多是用來管理數(shù)據(jù)庫。繼續(xù)加油。