Thinkphp 5 auth permission setting and implementation

[Thinkphp 5] auth permission setting and implementation

1. Download the auth class and place it in the directory: extend\auth\auth.php

2. Execute the SQL statement in the class, you can create 3 tables in the database auth_group (user group table) auth_rule (authorization rule table) auth_group_access (user and user group association table)

3. I want to add a level relationship to the rule (similar to infinite pole classification) auth_rule (authorization rule table) to add 3 fields pid (parent id, 0 is the top level authority) level (level) sort (sort), as shown below

Insert picture description here
4. First, create an administrator table by yourself, such as the admin table, add, delete, modify and check yourself to design normally, the group field is the user group to which it belongs

Insert picture description here
5. Add, delete, modify and check the auth_group user group and make it yourself, id, user group name, status (open or closed), rules (corresponding to the id of the rule table)

Insert picture description here
6. Add, delete, modify and check the auth_rule rule table and make it yourself, id, name (controller/method), title (rule name) status status (on or off),
Insert picture description here
7. When adding a user, select the user to belong to Group, uid (corresponding to the user id) group_id (corresponding to the id of the user group to which the user belongs), so they are associated

Insert picture description here
8. Make the member login function well, set the session('id') after the login is successful, and store the currently logged-in member ID in the session

9. The most critical step is to use the auth class for verification, which is used in the common page of common.php

Insert picture description here
Final display;

Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45557228/article/details/111031140