/** * 角色详情显示 */ public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_account_role_edit_get'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->digits()->min(1)->validate('meta_id'); $meta_id = $meta_id > 0 ? $meta_id : 0; if (!$this->validate($validator)) { goto out; } // 查询角色信息 $metaRoleService = new MetaRoleService(); $role = $metaRoleService->loadRoleById($meta_id); if (0 != $meta_id && $role->isEmpty()) { // 不存在的角色 $this->addFlashMessage('角色不存在'); goto out; } if ($role->isEmpty()) { // 新建角色 $this->requirePrivilege('manage_account_role_create'); } if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } // 权限检查 $this->requirePrivilege('manage_account_role_edit_post'); // 用户提交了更新请求,这里做角色信息更新 $validator = new Validator($f3->get('POST')); $metaRoleService->saveRole($meta_id, $validator->validate('meta_name'), $validator->validate('meta_desc'), $role['meta_data']); if (0 == $meta_id) { $this->addFlashMessage('成功新建角色'); } else { $this->addFlashMessage('角色信息更新成功'); } out_display: //给 smarty 模板赋值 $smarty->assign($role->toArray()); out: $smarty->display('account_role_edit.tpl'); }