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