1. Download the Auth class to a good place 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 (Permission rule table) auth_group_access (User and User Group Association table)
3. I want to add a level relationship to the rule (similar to the Infinite Pole classification) Auth_rule (the Permission Rules table) Add 3 fields PID (parent ID, 0 is the top level permission) level (rank) sort (sort), as
4, the first to create their own administrator table, such as called the admin table, adding and removing changes to the normal design, group field for the user group
5.auth_group User group additions and deletions to make the changes themselves, ID, user group name, status (open, or close), the rule (corresponding to the rule table ID)
6.auth_rule rules table additions and deletions also to make, Id,name (Controller/method), title (rule name) status state (open, or close),
7. When adding a user to the user to select the user group, UID (corresponding to the user ID) group_id (corresponding to the user's user group ID), so it is linked together
8. The member login function is done, login successfully set session (' ID '), the current login member ID exists in the session
9. The most critical step is to use the Auth class for validation, which is used in the common.php public page
1<?PHP2 namespace App\admin\controller;3 UseThink\controller;4 Usethink\request;5 UseAuth\auth;//introduction of Suth class6 classCommonextendsController7 { 8 Public function_initialize () {9 //Initialize to determine if the user has logged inTen if(!session (' uname ')){ One $this->error (' Please login the system first! ', ' Login/index '); A } - - the //get the Controller/method for the current page - $request=request::instance (); - $moudle=$request->module ();//gets the current controller name - $con=$request->controller ();//gets the current controller name + $action=$request->action ();//gets the current method name - $this->assign (Array( +' Con ' =$con, A' Action ' =$action, at )); - - $rules=$con.‘ /‘.$action;//Combination Controller/Method - $auth=NewAuth ();//instantiation of Auth class - $notCheck=Array(' Index/index ');//can access the page - if(Session (' UID ')!=1) {//It 's not a super administrator to judge permissions . in if(!In_array($rules,$notCheck)){//whether in open access - if(!$auth->check ($rules, session (' UID ')) {///First parameter control/method The second parameter: ID of the member currently logged in to $this->error (' No Permissions ', ' Index/index '); + }; - } the } * $ Panax Notoginseng - the}
Final display;
"Thinkphp 5" AUTH permission settings and implementation