ThinkPHP分组模式下使用RBAC的方法
如果不使用分组模式thinkphp RBAC 默认值是常量APP_NAME,而分组模式下则用常量GROUP_NAME获得当前分组名称.
关键代码:
RBAC::AccessDecision(GROUP_NAME)
以下是CommonAction.class.php的完整代码:
<?php
/*
* BaseAction.class.php
* Created on: 2013-4-14 16:01:04
* Author: Outsider <ioutsiderla@gmail.com>
* http://outsiderla.me
*/
class CommonAction extends Action {
function _initialize() {
import('@.ORG.Util.Cookie');
if (C('USER_AUTH_ON') && !in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE')))) {
import('@.ORG.Util.RBAC');
if (!RBAC::AccessDecision(GROUP_NAME)) {
if (!$_SESSION[C('USER_AUTH_KEY')]) {
$this->assign('jumpUrl', __APP__ . C('USER_AUTH_GATEWAY'));
$this->error('没有登录!请重新登录');
}
if (C('RBAC_ERROR_PAGE')) {
$this->assign('jumpUrl', __APP__ . C('RBAC_ERROR_PAGE'));
$this->error('对不起,没有权限');
} else {
if (C('GUEST_AUTH_ON')) {
$this->assign('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY'));
}
$this->error(L('_VALID_ACCESS_'));
}
}
}
}
}