码迷,mamicode.com
首页 > 其他好文 > 详细

Yii的srbac拓展中“用户已经获授权项”无法查看

时间:2015-05-06 12:48:30      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

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));
    }
  }

修改后就能看到效果了,效果如下

技术分享

如过不懂什么原因,可分析下源代码。

 

Yii的srbac拓展中“用户已经获授权项”无法查看

标签:

原文地址:http://www.cnblogs.com/ser0632/p/4481172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!