Home > php教程 > php手册 > Auth权限类使用示例

Auth权限类使用示例

WBOY
Release: 2016-06-07 11:44:03
Original
1453 people have browsed it

看了下官网上还没有一个Auth权限类实例应用,今天抽空写了下,希望对大家有所帮助

数据库如下
mc_admin_group

Field Type Allow Null Default Value
id mediumint(8) UNSIGNED No
title char(100) No
status tinyint(1) No 1
rules char(80) No

mc_admin_group_access

Field Type Allow Null Default Value
uid mediumint(8) UNSIGNED No
group_id mediumint(8) UNSIGNED No

mc_admin_menu

Field Type Allow Null Default Value
id smallint(6) No
name char(40) No
title varchar(50) No
condition varchar(60) No
pid smallint(6) No 0
g char(20) No
m char(20) No
a char(20) No
data char(30) No
listorder smallint(6) No 0
display enum('1','0') No '1'
status enum('1','0') No '1'

AdministratorAction.class.phpclass AdministratorAction extends Action{<br>     /**<br>      * 初始化<br>      */<br>     public function _initialize(){<br>         parent::_initialize();<br>         if($this->isLogin()){<br>             $this->checkRule();<br>         }<br>     }<br> <br>     /**<br>      * 判断是否登录<br>      * @return bool<br>      */<br>     public function isLogin(){<br>         if(!session(C('ADMIN_KEY'))){<br>             $this->redirect(C('ADMIN_GATEWAY'));<br>         }<br>         return true;<br>     }<br> <br>     /**<br>      * 检测是否有权限<br>      * @return bool<br>      */<br>     public function checkRule(){<br>         if( in_array(GROUP_NAME,array('Admin')) && in_array(MODULE_NAME,array('Index')) || session(C('ADMINISTRATOR'))) return true;<br>         $ruleName = '';<br>         $menu = S('menu')?S('menu'):D('AdminMenu')->cache_menu();<br>         foreach($menu as $v){<br>             if(GROUP_NAME == $v['g'] && MODULE_NAME == $v['m'] && ACTION_NAME == $v['a']){<br>                 $ruleName = $v['name'];<br>             }<br>         }<br>         $auth = new Auth();<br>         if(!$auth->check($ruleName,session(C('ADMIN_KEY')))){<br>             $this->error(L('LANG_NO_PERMISSION'),U(C('ADMIN_GATEWAY')));<br>         }<br>     }<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template