The Authority management basically is as standard of the website;
Unless it is used by individuals such as blogs, the importance of rights management is self-evident;
This is the right to write Auth rights management;
The thinkphp has built-in Auth permission classes at:/thinkphp/library/think/auth.class.php
Execute the SQL inside to generate 3 sheets of auth_rule, Auth_group, auth_group_access;
Then build yourself another users table, of course, other names are also possible, but need to be described in the configuration item;
First, the functions of the tables are briefly introduced;
Users: User table; this is not nonsense;
Auth_group: User Group table, such as Super Admins group, General Administrators group, editor, etc., and also record what permissions each management group has;
Auth_group_access: User, Group association table; For example, User 1 belongs to Super Administrator, user 2 belongs to General Administrator and editor;
Auth_rule: the permission table, and what each permission is;
If you have not seen the rights management, it is recommended to look at the source code first, thoroughly learn one thing, the best way is to study the source code;
The focus here is not to talk about Auth, but to give a auth demo;
Git source code: http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
1: First download the project and install;
After the completion of the separate point Super admin login and the article Administrator login;
You will find that their permissions are different; The background menu you see is not the same;
2: Menu Management
In order to control the menu that each administrator can see, the menu must be managed;
Operation is the Admin_nav table in the demo
3: Rights Management
The name and content of each of the specific permissions; I usually correspond with the menu;
But it will be more than the menu management, the comparison of the two pictures can be seen, more often than not the menu to change the additions and deletions;
Operation is the Auth_rule table in the demo;
4: User Group Management
This is the addition of administrative groups, and assigning permissions to each management group;
5: Administrator List
List all the administrators, can add the administrator or modify the administrator's management group;
When such a structure is built, the rights management is simply the AdminBaseController.class.php of the following code;
/application/common/controller/adminbasecontroller.class.php
$auth =new \think\auth ();
$rule _name=module_name. ' /‘. Controller_name. ' /‘. Action_name;
$result = $auth->check ($rule _name,$_session[' user '] [' id ']);
if (! $result) {
$this->error (' You do not have permission to access ');
}
This is also in the thinkphp of the directory structure design experience summary of/application/common/controller in the construction of various basecontroller reasons;
This article for Bai Jun Remote original article, reprinted without contact with me, but please specify from Bai Jun remote blog http://www.baijunyao.com
Thinkphp Integration series of RBAC upgrade version auth Rights Management System demo