PHP.48-TP Framework Mall Application Example-background 23-Rights Management-permission validation

Source: Internet
Author: User

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

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.