<?php |
class RbacAction extends CommonAction{ |
public function addRole(){ |
$this ->display(); |
} |
//添加角色表单处理 |
public function addRoleHandle(){ |
if (M( 'Role' )->add( $_POST )){ |
$this ->success( '添加成功!' ,U( 'rbac/addrole' )); |
} |
} |
//角色管理(角色列表) |
public function roleList(){ |
$this ->role=M( 'Role' )->select(); |
$this ->display(); |
} |
// 添加权限(节点) |
public function addNode(){ |
$this ->node=M( 'Node' )->where( 'level!=3' )->order( 'sort' )->select(); |
$this ->display(); |
} |
// 添加节点表单处理 |
public function addNodeHandle(){ |
$node =M( 'Node' ); |
$node ->create(); |
if ( $node ->add()){ |
$this ->success( '添加成功!' ,U( 'rbac/nodeList' )); |
} |
} |
// 权限管理(节点列表) |
public function nodeList(){ |
import( 'ORG.Util.Tree' ); |
$node =M( 'Node' )->order( 'sort' )->select(); |
$this ->node=Tree::create( $node ); |
$this ->display(); |
} |
//删除权限(节点) |
public function deletenode(){ |
if (M( 'Node' )->where( 'id=' .I( 'id' , '' ,int))-> delete ()){ |
$this ->success( '删除成功!' ,U( 'rbac/nodeList' )); |
} |
} |
public function addUser(){ |
$this ->role=M( 'Role' )->select(); |
$this ->display(); |
} |
//添加用户处理 |
public function addUserHandle(){ |
$data [ 'username' ]=I( 'username' ); |
$data [ 'password' ]=I( 'password' , '' , 'md5' ); |
$data [ 'logintime' ]=time(); |
$data [ 'loginip' ]=get_client_ip(); |
$data [ 'status' ]=1; |
$uid =M( 'User' )->add( $data ); |
if ( $uid ){ |
//用户添加成功后添加用户角色表 |
$role [ 'role_id' ]=I( 'role_id' , '' ,int); |
$role [ 'user_id' ]= $uid ; |
$this ->success( '添加成功!' ,U( 'rbac/addUser' )); |
} else { |
$this ->error( '添加失败!' ); |
} |
} |
//用户列表 |
public function userList(){ |
$this ->user=D( 'User' )->field( 'password' ,true)->relation(true)->select(); |
$this ->display(); |
} |
//配置权限 |
public function access(){ |
import( 'ORG.Util.Tree' ); |
$rid =I( 'rid' , '' ,int); |
$node =M( 'Node' )->order( 'sort' )->select(); |
$this ->node=Tree::create( $node ); |
$data = array (); //$data用于存放最新数组,里面包含当前用户组是否有每一个权限 |
$access =M( 'Access' ); |
foreach ( $node as $value ) { |
$count = $access ->where( 'role_id=' . $rid . ' and node_id=' . $value [ 'id' ])-> count (); |
if ( $count ){ |
$value [ 'access' ]=1; |
} else { |
$value [ 'access' ]=0; |
} |
$data []= $value ; |
} |
$this ->nodelist= $data ; |
$this ->rid= $rid ; |
$this ->name=M( 'Role' )->getFieldById( $rid , 'name' ); |
$this ->display(); |
} |
//添加角色-权限表(节点表) |
public function setAccess(){ |
$rid =I( 'rid' , '' ,int); |
$access =M( 'Access' ); |
$access ->where( 'role_id=' . $rid )-> delete (); //清空当前角色的所有权限 |
|
if (isset( $_POST [ 'access' ])){ |
$data = array (); |
foreach ( $_POST [ 'access' ] as $value ){ |
$tmp = explode ( '_' , $value ); |
$data []= array ( |
'role_id' => $rid , |
'node_id' => $tmp [0], |
'level' => $tmp [1], |
); |
} |
if ( $access ->addAll( $data )){ |
$this ->success( '修改成功!' ,U( 'rbac/addRole' )); |
} else { |
$this ->error( '修改失败!' ,U( 'rbac/access' ),60); |
} |
} else { |
$this ->error( '修改失败!' ); |
} |
} |
} |
初级程序员
by: m530787997 发表于:2020-03-30 21:16:58 顶(0) | 踩(0) 回复
按照题主的来,无限极那块老是提示class 'Admin\Controller\Tree' not found,大佬在可以解答下吗
回复评论