<?php namespace app\admin\controller; use Util\SysDb; use think\facade\Request; use app\admin\model\AdminModel; class Menu extends Base { // 编辑操作 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'=>'数据删除成功']; } }