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();
}