ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 代码 > 注意:如果不需要插入 `auth_rule` 表,`注释一` 部分代码可以不要 > 注意:如果不需要导出,`注释二` 部分代码可以不要 ``` <?php namespace app\agent\controller; use think\Controller; use think\Db; class MenuController extends Controller { /** * 后台菜单编辑提交保存 */ public function editPost() { if ($this->request->isPost()) { $id = $this->request->param('id', 0, 'intval'); $oldMenu = Db::name('AdminMenu')->where(['id' => $id])->find(); $result = $this->validate($this->request->param(), 'AdminMenu.edit'); if ($result !== true) { $this->error($result); } else { Db::name('AdminMenu')->strict(false)->field(true)->update($this->request->param()); // 注释一:下边全部是对 auth_rule 操作 // $app = $this->request->param("app"); // $controller = $this->request->param("controller"); // $action = $this->request->param("action"); // $param = $this->request->param("param"); // $authRuleName = "$app/$controller/$action"; // $menuName = $this->request->param("name"); // // $findAuthRuleCount = Db::name('auth_rule')->where([ // 'app' => $app, // 'name' => $authRuleName, // 'type' => 'admin_url' // ])->count(); // if (empty($findAuthRuleCount)) { // $oldApp = $oldMenu['app']; // $oldController = $oldMenu['controller']; // $oldAction = $oldMenu['action']; // $oldName = "$oldApp/$oldController/$oldAction"; // $findOldRuleId = Db::name('AuthRule')->where(["name" => $oldName])->value('id'); // if (empty($findOldRuleId)) { // Db::name('AuthRule')->insert([ // "name" => $authRuleName, // "app" => $app, // "type" => "admin_url", // "title" => $menuName, // "param" => $param // ]); // } else { // Db::name('AuthRule')->where(['id' => $findOldRuleId])->update([ // "name" => $authRuleName, // "app" => $app, // "type" => "admin_url", // "title" => $menuName, // "param" => $param]); // } // } else { // Db::name('AuthRule')->where([ // 'app' => $app, // 'name' => $authRuleName, // 'type' => 'admin_url' // ])->update(["title" => $menuName, 'param' => $param]); // } // 注释二:导出数据 // $this->_exportAppMenuDefaultLang(); $this->success("保存成功!"); } } } } ```