abstract:<?php /** * Created by PhpStorm. * User: Jason * Date: 2019/5/5 * Time: 23:29 */ namespace app\admin\controller; us
<?php /** * Created by PhpStorm. * User: Jason * Date: 2019/5/5 * Time: 23:29 */ namespace app\admin\controller; use Util\SysDb; use think\facade\Request; use app\admin\model\AdminModel; class Menu extends Base { public function index(){ $data['lists'] = SysDb::getnstance()->table('admin_menus')->order('ord asc')->lists(); return $this->fetch('',$data); } // 添加菜单 public function add() { return $this->fetch(); } // 添加操作 public function doAdd() { $data = Request::param(); if($data['title'] == '') { return ['code'=>0,'msg'=>'菜单名称不能为空']; } if($data['controller'] == '') { return ['code'=>0,'msg'=>'控制器名称不能为空']; } if($data['method'] == '') { return ['code'=>0,'msg'=>'方法名称不能为空']; } $data['pid'] = 0; // 进行写入操作 $ins = SysDb::getnstance()->table('admin_menus')->insert($data); if(!$ins) { return ['code'=>0,'msg'=>'数据保存失败,请稍后重试']; } return ['code'=>1,'msg'=>'数据保存成功']; } // 编辑操作 public function edit() { $id = Request::param('mid'); // 根据ID查询数据并渲染页面m $data = SysDb::getnstance()->table('admin_menus')->where(['mid'=>$id])->item(); // 模板赋值 $this->assign('data',$data); // 渲染模板 return $this->fetch(); } // 处理编辑 public function doEdit() { $data = Request::param(); $mid = $data['mid']; unset($data['mid']); if($data['title'] == '') { return ['code'=>0,'msg'=>'菜单名称不能为空']; } if($data['controller'] == '') { return ['code'=>0,'msg'=>'控制器名称不能为空']; } if($data['method'] == '') { return ['code'=>0,'msg'=>'方法名称不能为空']; } $up = SysDb::getnstance()->table('admin_menus')->where(['mid'=>$mid])->update($data); if(!$up) { return ['code'=>0,'msg'=>'数据编辑失败']; } return ['code'=>1,'msg'=>'数据编辑成功']; } // 数据删除 public function doDel() { $mid = Request::param('mid'); $del = SysDb::getnstance()->table('admin_menus')->where(['mid'=>$mid])->del(); if(!$del) { return ['code'=>0,'msg'=>'数据删除失败']; } return ['code'=>1,'msg'=>'数据删除成功']; } }
Correcting teacher:查无此人Correction time:2019-05-08 09:39:12
Teacher's summary:完成的不错。后台cms系统,最主要的就是对数据库增删查改。继续加油。