dwz1.4.3 无限级左边栏菜单

表结构及测试数据如下:

在common.php共用函数里面加入:

  1. //将数组转化为树形数组  
  2.  function arrToTree($data,$pid){  
  3.         $tree = array();  
  4.         foreach($data as $k => $v){  
  5.             if($v['pid'] == $pid){  
  6.                 $v['pid'] = arrToTree($data,$v['id']);  
  7.                 $tree[] = $v;  
  8.             }  
  9.         }          
  10.         return $tree;  
  11.  }  
  12.  //左边菜单栏输出  
  13.  function outMenu($group,$tree){  
  14.     $html = '';  
  15.     foreach($tree as $t){  
  16.       if($t['group_id']==$group){  
  17.         if(empty($t['pid'])){  
  18.             $html .= '<li><a href="'.__APP__.'/'.$t['name'].'/index/" target="navTab" rel="'.$t['name'].'">'.$t['title'].'</a></li>';  
  19.         }else{  
  20.             $html .='<li><a>'.$t['title'].'</a><ul>';  
  21.             $html .=outMenu($group,$t['pid']);  
  22.             $html  = $html.'</ul></li>';  
  23.         }  
  24.       }  
  25.     }   
  26.     return $html;  
  27.  }  

indexAction.class.php:
  1. public function index() {  
  2.         if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {  
  3.             //显示菜单项  
  4.             $menu = array ();  
  5.               
  6.             //读取数据库模块列表生成菜单项  
  7.             $node = M ( "Node" );  
  8.             $where ['status'] = 1;  
  9.             $where ['group_id'] = array(array('exp','is not null'),array('neq',0));  
  10.             $list = $node->where ( $where )->field ( 'ID,PID,NAME,GROUP_ID,TITLE' )->order ( 'group_id,level_id,sort' )->select ();  
  11.             $gList = $node->where($where)->getField('id,group_id');  
  12.             $accessList = $_SESSION ['_ACCESS_LIST'];  
  13.             foreach ( $list as $key => $module ) {  
  14.                 if (isset ( $accessList [strtoupper ( APP_NAME )] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {  
  15.                     //设置模块访问权限  
  16.                     $module ['access'] = 1;  
  17.                     $menu [$key] = $module;  
  18.                 }  
  19.             }                         
  20.             $groupM = D('Group');  
  21.             $groupMap['status'] = 1;  
  22.             $groupMap['id'] = array('in',array_flip(array_flip($gList)));  
  23.             $groupList = $groupM->where($groupMap)->order('sort asc')->select();  
  24.                           
  25.             $menu = arrToTree($menu,0);  
  26.   
  27.             if (! empty ( $_GET ['tag'] )) {  
  28.                 $this->assign ( 'menuTag'$_GET ['tag'] );  
  29.             }  
  30.             //dump($menu);  
  31.             $this->assign ( 'groupList'$groupList );  
  32.             $this->assign ( 'menu'$menu );  
  33.         }  
  34.         C ( 'SHOW_RUN_TIME', false ); // 运行时间显示  
  35.         C ( 'SHOW_PAGE_TRACE', false );  
  36.         $this->display ();  
  37.     }  

模板menu.html:
  1. <div class="accordion" fillSpace="sideBar">  
  2.   <volist id="v1" name="groupList" >  
  3.     <div class="accordionHeader">  
  4.         <h2><span>Folder</span>{$v1.title}</h2>  
  5.     </div>  
  6.     <div class="accordionContent">      
  7.         <ul class="tree treeFolder">  
  8.         {$v1['id']|outMenu=$menu}  
  9.         </ul>      
  10.     </div>  
  11.   </volist>  
  12. </div>  

最终效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值