标签:
Yii的srbac拓展中“用户已经获授权项”点下拉框,选择一个有权限的用户时,根本无法列出权限。
原因是srbac把数据库的表中的ID默认为数字,像 123这样,但如果不是数字像这样 ‘y0f22ffc2fef712fd602a1ef64ab319t‘ 。那么这个是不会出来的,那么只能修改代码 了。
修改 \protected\modules\srbac\controllers\AuthitemController.php 文件中的 actionShowAssignments 方法
源代码如下
public function actionShowAssignments() { $userid = isset($_GET["id"]) ? $_GET["id"] : $_POST[Helper::findModule(‘srbac‘)->userclass][$this->module->userid]; $user = $this->module->getUserModel()->findByPk($userid); $username = $user->{$this->module->username}; $r = array(0 => array(0 => array())); if ($userid > 0) { $auth = Yii::app()->authManager; /* @var $auth CDbAuthManager */ $ass = $auth->getAuthItems(2, $userid); $r = array(); foreach ($ass as $i => $role) { $curRole = $role->name; $r[$i] = $curRole; $children = $auth->getItemChildren($curRole); $r[$i] = array(); foreach ($children as $j => $task) { $curTask = $task->name; $r[$i][$j] = $curTask; $grandchildren = $auth->getItemChildren($curTask); $r[$i][$j] = array(); foreach ($grandchildren as $k => $oper) { $curOper = $oper->name; $r[$i][$j][$k] = $curOper; } } } // Add always allowed opers $r["AlwaysAllowed"][""] = $this->module->getAlwaysAllowed(); $this->renderPartial(‘userAssignments‘, array(‘data‘ => $r, ‘username‘ => $username)); } }
我们把第 7 行的判断语句修改下 if ($userid > 0)
修改成 if (count($user)> 0) ,即可,修改后代码如下
public function actionShowAssignments() { $userid = isset($_GET["id"]) ? $_GET["id"] : $_POST[Helper::findModule(‘srbac‘)->userclass][$this->module->userid]; $user = $this->module->getUserModel()->findByPk($userid); $username = $user->{$this->module->username}; $r = array(0 => array(0 => array())); if (count($user) > 0) { $auth = Yii::app()->authManager; /* @var $auth CDbAuthManager */ $ass = $auth->getAuthItems(2, $userid); $r = array(); foreach ($ass as $i => $role) { $curRole = $role->name; $r[$i] = $curRole; $children = $auth->getItemChildren($curRole); $r[$i] = array(); foreach ($children as $j => $task) { $curTask = $task->name; $r[$i][$j] = $curTask; $grandchildren = $auth->getItemChildren($curTask); $r[$i][$j] = array(); foreach ($grandchildren as $k => $oper) { $curOper = $oper->name; $r[$i][$j][$k] = $curOper; } } } // Add always allowed opers $r["AlwaysAllowed"][""] = $this->module->getAlwaysAllowed(); $this->renderPartial(‘userAssignments‘, array(‘data‘ => $r, ‘username‘ => $username)); } }
修改后就能看到效果了,效果如下
如过不懂什么原因,可分析下源代码。
标签:
原文地址:http://www.cnblogs.com/ser0632/p/4481172.html