ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 控制器 ## 代码 ``` <?php namespace app\agent\controller; use think\Controller; use think\Db; class UserController extends Controller { /** * 管理员编辑提交 */ public function editPost() { if ($this->request->isPost()) { if (!empty($_POST['role_id']) && is_array($_POST['role_id'])) { if (empty($_POST['user_pass'])) { unset($_POST['user_pass']); } else { $_POST['user_pass'] = cmf_password($_POST['user_pass']); } $role_ids = $this->request->param('role_id/a'); unset($_POST['role_id']); $result = $this->validate($this->request->param(), 'User.edit'); if ($result !== true) { // 验证失败 输出错误信息 $this->error($result); } else { $result = DB::name('user')->update($_POST); if ($result !== false) { $uid = $this->request->param('id', 0, 'intval'); DB::name("RoleUser")->where(["user_id" => $uid])->delete(); foreach ($role_ids as $role_id) { if (cmf_get_current_admin_id() != 1 && $role_id == 1) { $this->error("为了网站的安全,非网站创建者不可创建超级管理员!"); } DB::name("RoleUser")->insert(["role_id" => $role_id, "user_id" => $uid]); } $this->success("保存成功!"); } else { $this->error("保存失败!"); } } } else { $this->error("请为此用户指定角色!"); } } } } ```