Thinkphp3.2 cms之权限管理
五、权限管理
<?php namespace Admin\Controller; use Think\Controller; class CommonController extends Controller { protected $admin=array(); protected function _initialize() { $this->admin=session('admin'); if (strtolower(CONTROLLER_NAME) != 'login') { if (empty($this->admin)) { redirect(U('Login/login')); exit(); } } $nownav['m']=strtolower(CONTROLLER_NAME ); $nownav['a']=strtolower(ACTION_NAME); $this->assign('nownav',$nownav); $this->assign('admin',$this->admin); //查询当前登录用户的角色id $role_ids=M('role_user')->where(array('user_id'=>$this->admin['uid']))->find(); // 查询当前角色的权限 $this->admin['list']=M('node_access')->where(array('r_id'=>$role_ids['role_id']))->find(); $menu=M('node')->select(); $map=array(); foreach( $this->admin['list'] as $val){ $map=explode(",",$val); } for($i=0;$i<count($map);$i++) { $menu[]=D('node')->where(array("n_id"=>$map[$i]))->select(); } $this->assign('menu',$menu); } }