最新消息: 新版网站上线了!!!

thinkphp rbac显示菜单的方法

  1. $aclList = array
  2.         'Index' => array('name'=>'系统管理','mod'=>'Index','icon'=>'fa-home','url'=>'Index/index','list'=>array
  3.             array('name' => '系统主页''url' => 'Index/index','act'=>'index'), 
  4.             array('name' => '基本设置''url' => 'Index/editWebinfo','act'=>'editWebinfo'), 
  5.             array('name' => '刷新缓存''url' => 'Index/flushCache','act'=>'flushCache'), 
  6.             array('name' => '添加充值方式''url' => 'Index/sendMethod','act'=>'sendMethod'), 
  7.             array('name' => '管理充值方式''url' => 'Index/manageMethod','act'=>'manageMethod'), 
  8.         )), 
  9.         'User' => array('name'=>'用户管理','mod'=>'User','icon'=>'fa-columns','url'=>'User/index','list'=>array
  10.             array('name' => '会员列表''url' => 'User/showAllusers','act'=>'showAllusers'), 
  11.             array('name' => '修改密码''url' => 'User/editPassword','act'=>'editPassword'), 
  12.         )), 
  13.  
  14.     ); 
  15. if (C('USER_AUTH_ON') && emptyempty($_SESSION[C('ADMIN_AUTH_KEY')])) { 
  16.             if (C('USER_AUTH_TYPE') == 2) { 
  17.                 //加强验证和即时验证模式 
  18.                 import('ORG.Util.RBAC'); 
  19.                 $accessList = RBAC::getAccessList($_SESSION[C('USER_AUTH_KEY')]); 
  20.             } else { 
  21.                 $accessList = $_SESSION['_ACCESS_LIST']; 
  22.             } 
  23.         } 
  24.       //打印出$accessList 找到第一个ADmin
  25.         $_menu = array(); 
  26.         foreach ($aclList as $key=>$val) { 
  27.             $_key = strtoupper($key); 
  28.             if(array_key_exists($_key,$accessList['ADMIN'])) { 
  29.                 foreach ($val['list'as $k=>$v) { 
  30.                     if(!array_key_exists(strtoupper($v['act']),$accessList['ADMIN_BITCOIN'][$_key])) { 
  31.                         unset($val['list'][$k]); 
  32.                     } 
  33.                 } 
  34.                 $_menu[$key] = $val
  35.             } 
  36.         } 
  37. $this->assign('meun',$_menu); 

meun.html

 

  1. <volist name="meun" id="data"> 
  2.                     <!--active --> 
  3.                     <li  <if condition="$Think.const.MODULE_NAME eq $data['mod']">class="active"</if>> 
  4.                     <a href="<{:U($data['url'])}>"> 
  5.                         <i class="fa <{$data.icon}>"></i> 
  6.                         <span class="nav-label"><{$data.name}></span> 
  7.                         <span class="fa arrow"></span> 
  8.                     </a> 
  9.  
  10.                     <ul class="nav nav-second-level"> 
  11.                         <volist name="data.list" id="vo_1" key="key_1"> 
  12.                             <!--activemenu--> 
  13.                             <li <if condition="$Think.const.MODULE_NAME eq $data['mod']  && $Think.const.ACTION_NAME eq $vo_1['act']">class="activemenu"</if>><a href="<{:U($vo_1['url'])}>"><{$vo_1['name']}></a></li> 
  14.                         </volist> 
  15.                     </ul> 
  16.                     </li> 
  17.                 </volist> 

 

转载请注明:谷谷点程序 » thinkphp rbac显示菜单的方法