Пример #1
0
/**
 * 递归重组节点信息
 */
function node_merges($node, $access = null, $pid = 0)
{
    $arr = array();
    foreach ($node as $v) {
        if (is_array($node)) {
            $v['access'] = in_array($v['id'], $access) ? 1 : 0;
        }
        if ($v['pid'] == $pid) {
            $v['child'] = node_merges($node, $access, $v['id']);
            $arr[] = $v;
        }
    }
    return $arr;
}
Пример #2
0
 public function rbac()
 {
     $id = I('id', 0, 'intval');
     if (IS_POST) {
         $data['rules'] = implode(',', I('node'));
         if ($this->model->where(array('id' => $id))->save($data)) {
             $this->success('授权成功', U('Role/index'));
         } else {
             $this->error('授权失败');
         }
     } else {
         /*查询权限组id*/
         $infoRule = $this->model->where(array('id' => $id))->getField('rules');
         $infoRule = explode(',', $infoRule);
         $this->order = array('sort', 'id' => 'desc');
         $node = $this->info_com($this->modelNode, '', $this->order);
         $this->list = node_merges($node, $infoRule);
         $this->id = $id;
         $this->display();
     }
 }
Пример #3
0
 /**
  * [ruleList 获取权限列表]
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function ruleList($id)
 {
     $rules = $this->Auth->getGroups($id);
     $rbac = $this->Auth->getRules($rules[0]['rules']);
     return node_merges($rbac);
 }