您的位置:首页 > 编程语言 > PHP开发

thinkphp RBAC权限节点递归

2016-05-15 15:50 567 查看
Common/function.php
//权限节点递归
/**
* [getTree description]
* @param  [type]  $node   总权限节点
* @param  [type]  $access 自身权限节点
* @param  integer $pid    [description]
* @return [type]          [description]
*/
function getTree($node,$access=null,$pid=0){
$tree = array();
foreach ($node as $v) {
if(is_array($access)){
$v['access'] = in_array($v['id'], $access) ? 1:0;
}
if($v['pid'] == $pid){
$v['child'] = getTree($node,$access,$v['id']);
$tree[] = $v;
}
}
return $tree;
}
//给角色配置节点
public function access(){
$rid = I('rid');
//原有权限
$access = M('access')->where(array('role_id' => $rid))->getField('node_id',true);
$node = M('node')->select();
$node1 = getTree($node,$access);
$this->display();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: