Thinkphp RBAC Implementation principle

Source: Internet
Author: User

RBAC is an abbreviation of English role-based access control and a mechanism for controlling role-based access. It means setting a role for each user and then judging the user's permissions based on the role.

This is a simple summary of the thinkphp-based MVC pattern (thinkphp access is controlled by both the module and the operating section).

RBAC is generally composed of five tables, namely:

1. User tables

2. User Group table

3. Module table

4. Method table

5. User groups-Method table

As shown

When a user accesses a page, it is possible to get the ID of the current user through the session through the Thinkphp system constants module_name and Action_name.

Let all the modules of the site inherit one aclaction, while Aclaction inherits to the action.

Defining an initialization function in aclaction public function _initialize () {}, which means that the function is executed when a user accesses any page on the Web site.

In the Initialize () function, get the user ID, ModuleName, actionname, through the user ID database query to obtain the user group ID, the user group ID, modulename, actionname to the database in a long table connection query, Find Group-action-action-module in the presence of Groupip, ModuleID, ActionId Records, if there is the user has access to the current page, otherwise, the use of thinkphp built-in function $ This->error () to make a reminder and jump to the landing page.

At this point, the entire RBAC permissions to control the process of completion, the user rights authentication completed.

Thinkphp RBAC Implementation principle

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.