Example of using the Auth permission class

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. After reading this article, I have not provided an Auth permission instance application on the official website. Today I took the time to write it down, hope to help you

The database is as follows:
Mc_admin_group

FieldTypeAllow NullDefault Value
Idmediumint (8) UNSIGNEDNo
Titlechar (100) No
Statustinyint (1) No1
Ruleschar (80) No

Mc_admin_group_access

FieldTypeAllow NullDefault Value
Uidmediumint (8) UNSIGNEDNo
Group_idmediumint (8) UNSIGNEDNo

Mc_admin_menu

FieldTypeAllow NullDefault Value
Idsmallint (6) No
Namechar (40) No
Titlevarchar (50) No
Condition varchar (60) No
Pidsmallint (6) No0
Gchar (20) No
Mchar (20) No
Achar (20) No
Datachar (30) No
Listordersmallint (6) No0
Displayenum ('1', '0') No '1'
Statusenum ('1', '0') No '1'

Administratexception. class. php Class administratexception extends Action {
/**
* Initialization
*/
Public function _ initialize (){
Parent: _ initialize ();
If ($ this-> isLogin ()){
$ This-> checkRule ();
}
}

/**
* Determine whether to log on
* @ Return bool
*/
Public function isLogin (){
If (! Session (C ('admin _ key '))){
$ This-> redirect (C ('admin _ gateway '));
}
Return true;
}

/**
* Check for Permissions
* @ Return bool
*/
Public function checkRule (){
If (in_array (GROUP_NAME, array ('admin') & in_array (MODULE_NAME, array ('index') | session (C ('admin '))) return true;
$ RuleName = '';
$ Menu = S ('menu ')? S ('menu '): D ('adminmenu')-> cache_menu ();
Foreach ($ menu as $ v ){
If (GROUP_NAME = $ v ['G'] & MODULE_NAME = $ v ['M'] & ACTION_NAME = $ v ['a']) {
$ RuleName = $ v ['name'];
}
}
$ Auth = new Auth ();
If (! $ Auth-> check ($ ruleName, session (C ('admin _ key ')))){
$ This-> error (L ('lang _ NO_PERMISSION '), U (C ('admin _ gateway ')));
}
}
}

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.