Here, the main supplement is the configuration and related code issues.
<?PHPreturn Array( //' Config item ' = ' config value '' Rbac_superadmin ' = ' admin ',//Super administrator name, corresponding to one user in the user table: Username' Admin_auth_key ' = ' superadmin ',//Super Administrator Identification' User_auth_on ' =true,//whether certification is required' User_auth_type ' = 1,//Authentication Type 1-post-login authentication, 2-real-time authentication' User_auth_key ' = ' authId ',//authentication identification number, where you can customize//' require_auth_module ' + ',//Require authentication module' Not_auth_module ' = ' user,index,safe ',//No authentication module required, and repeat above' Not_auth_action ' = ' addrolehandle,addnodehandle,adduserhandle,accesshandle ',//No certification action required//' user_auth_gateway ' = ',//authentication gateway, can not be used here//' rbac_db_dsn ' = ',//database connection DSN' rbac_role_table ' = ' tp_role ',//Role Table Name' rbac_user_table ' = ' tp_role_user ',//User table name' rbac_access_table ' = ' tp_access ',//Permission Table name' rbac_node_table ' = ' tp_node ',//Node Table name
This column as a menu, must have its corresponding code:
//left menu Public functionLeft () {//Var_dump (Session (' Role-id ')); $thisAssign ("Ouba", Session (' Role-id '))); //Super Admin if(The session (C (' Admin_auth_key '))){ $node= D (' Tp_node ')->relation (true), where (' level = 2 '), order (' sort ')Select (); }Else{ //Remove all permissions nodes $node= D (' Tp_node ')->relation (true), where (' level = 2 '), order (' sort ')Select (); //Remove all permissions for the currently logged on user (English name) and operation permissions $module= ' '; $node _id= ' '; $accessList=$_session[' _access_list ']; foreach($accessList as $key=$value){ foreach($value as $key 1=$value 1){ $module=$module.‘,‘.$key 1; foreach($value 1 as $key 2=$value 2){ //$node _id = $node _id. ', '. $key 2; $node _id=$node _id.‘,‘.$value 2; } } } //Remove a node without permissions foreach($node as $key=$value){ if(!In_array(Strtoupper($value[' name ']),Explode(‘,‘,$module))){ unset($node[$key]); } Else{ //module exists, compare the operation inside foreach($value[' node '] as $key 1=$value 1){ //if (!in_array (Strtoupper ($value 1[' name "), Explode (', ', $node _id))) { if(!In_array(Strtoupper($value 1[' ID ']),Explode(‘,‘,$node _id))){ unset($node[$key[' node '] [$key 1]);//One layer at a down, delete this action } } } } } $thisAssign (' node ',$node); $this-display (); }
Note: This function method is mainly for the processing of the permissions of the node, where the use of "large D", then in model, must have its corresponding mapping relationship:
<?phpnamespace Manage\model; UseThink\model\relationmodel;classTpnodemodelextendsrelationmodel{protected $_link=Array( ' Tp_node ' =Array( ' Mapping_type ' + self::has_many, ' parent_key ' = ' pid ',//' class_name ' = ' article ',' Foreign_key ' + ' id ', ' mapping_name ' = ' node ',//' mapping_order ' = ' create_time desc ', ), );}?>
thinkphp Project Note RBAC (permissions) Supplement