zoukankan      html  css  js  c++  java
  • Yii的srbac拓展中“用户已经获授权项”无法查看

    Yii的srbac拓展中“用户已经获授权项”点下拉框,选择一个有权限的用户时,根本无法列出权限。

    原因是srbac把数据库的表中的ID默认为数字,像 123这样,但如果不是数字像这样 'y0f22ffc2fef712fd602a1ef64ab319t' 。那么这个是不会出来的,那么只能修改代码 了。

    修改    protectedmodulessrbaccontrollersAuthitemController.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));
        }
      }

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

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

  • 相关阅读:
    如何手工设置归档目录
    C#字符串格式化说明(String.Format) (zz.IS2120)
    win7 GodMode
    金山软件公司创始人求伯君简介 (is2120.zz)
    【百度地图】安卓系统的百度地图可以下载离线地图,这个很省流量和时间
    手机用笔记本wifi上网【无USB、无软件、无无线路由器】
    安卓版有道词典的离线词库《21世纪大英汉词典》等
    秀秀我的巨无霸手机P1000
    [转载]环游澳大利亚18天——前传与攻略
    [转载]环游澳大利亚18天——前传与攻略
  • 原文地址:https://www.cnblogs.com/ser0632/p/4481172.html
Copyright © 2011-2022 走看看