Permission validation
1. Login Controller
2. Generate verification code image by TP Verification code class
3. Add login validation rules to administrator model
4 . All controllers in the background must be logged in before accessing
idea: before you access any controller, you can,=> add a parent controller to verify session
Let all the back-end controllers "except the login controller" inherit from this controller
5, before the administrator access to any of the background of the page before the database to see whether the role of the current administrator has access to this page
This check method is added in the permission model and is called in the parent class login controller .
6 . The left side of the background only shows the buttons that the current administrator has permission to access
idea : Take out the current administrator has the first two levels of permissions, in the left loop these permissions as buttons!
Adding methods to get current administrator permissions in the permissions model
/******** Gets the permissions of the first two levels currently owned by the Administrator ***********/ Public functionGetbtns () {//First, remove all permissions that are currently owned by the administrator $adminId= Session (' ID '); if($adminId= = 1) { $priModel= M (' privilege '); $priData=$priModel-Select (); } Else { //Remove the permissions that are owned by the current administrator's role $arModel= M (' Admin_role '); $priData=$arModel->alias (' a ') ->field (' DISTINCT c.id, c.pri_name,c.module_name,c.controller_name,c.action_name,c.parent_id ') -Join(‘Left join __role_pri__ B in a.role_id=b.role_id left join __privilege__ C on B.pri_id=c.id‘) ->where (Array( ' a.admin_id ' =Array(' eq ',$adminId), ))-Select (); } /*************** from all the top level two *******************/ $btns=Array();//Top Level Two permissions foreach($priData as $k=$v) { if($v[' parent_id '] = = 0) { //and find the child of this top. foreach($priData as $k 1=$v 1) { if($v 1[' parent_id '] = =$v[' ID ']) { $v[' Children '] [] =$v 1; } } $btns[] =$v; } } return $btns; }
Using the four-dimensional function output in menu.html
7. Add an Exit Account function in admin model = Delete session
PHP.48-TP Framework Mall Application Example-background 23-Rights Management-permission validation