Thinkphp Integration series of RBAC upgrade version auth Rights Management System demo

Source: Internet
Author: User

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;

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160514/1463186682405819.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

2: Menu Management

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160504/1462291919136306.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

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

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160504/1462291929640930.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

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

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160504/1462291949928045.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

This is the addition of administrative groups, and assigning permissions to each management group;

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160504/1462291962384468.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

5: Administrator List

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160514/1463186286405414.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

List all the administrators, can add the administrator or modify the administrator's management group;

650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160514/1463186391769769.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>

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://baijunyao.com


Thinkphp Integration series of RBAC upgrade version auth Rights Management System demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.