欢迎各位兄弟 发布技术文章
这里的技术是共享的
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
if($auth->check('show_button',1)){// 第一个参数是规则名称,第二个参数是用户UID
//有显示操作按钮的权限
}else{
//没有显示操作按钮的权限
}
复制代码
<?php
class CommonAction extends Action{
public function _initialize(){
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
if(!$auth->check(MODULE_NAME.'-'.ACTION_NAME,session('uid'))){
$this->error('你没有权限');
}
}
}
复制代码
$auth->check('rule1,rule2',uid);
复制代码
$auth->check('rule1,rule2',uid,'and');
复制代码
$auth->getGroups(uid)
复制代码
'AUTH_CONFIG'=>array(
'AUTH_ON' => true, //认证开关
'AUTH_TYPE' => 1, // 认证方式,1为时时认证;2为登录认证。
'AUTH_GROUP' => 'think_auth_group', //用户组数据表名
'AUTH_GROUP_ACCESS' => 'think_auth_group_access', //用户组明细表
'AUTH_RULE' => 'think_auth_rule', //权限规则表
'AUTH_USER' => 'think_members'//用户信息表
)
复制代码
-- ----------------------------
-- think_auth_rule,规则表,
-- id:主键,name:规则唯一标识, title:规则中文名称 status 状态:为1正常,为0禁用,condition:规则表达式,为空表示存在就验证,不为空表示按照条件验证
-- ----------------------------
DROP TABLE IF EXISTS `think_auth_rule`;
CREATE TABLE `think_auth_rule` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`name` char(80) NOT NULL DEFAULT '',
`title` char(20) NOT NULL DEFAULT '',
`status` tinyint(1) NOT NULL DEFAULT '1',
`condition` char(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- think_auth_group 用户组表,
-- id:主键, title:用户组中文名称, rules:用户组拥有的规则id, 多个规则","隔开,status 状态:为1正常,为0禁用
-- ----------------------------
DROP TABLE IF EXISTS `think_auth_group`;
CREATE TABLE `think_auth_group` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`title` char(100) NOT NULL DEFAULT '',
`status` tinyint(1) NOT NULL DEFAULT '1',
`rules` char(80) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- think_auth_group_access 用户组明细表
-- uid:用户id,group_id:用户组id
-- ----------------------------
DROP TABLE IF EXISTS `think_auth_group_access`;
CREATE TABLE `think_auth_group_access` (
`uid` mediumint(8) unsigned NOT NULL,
`group_id` mediumint(8) unsigned NOT NULL,
UNIQUE KEY `uid_group_id` (`uid`,`group_id`),
KEY `uid` (`uid`),
KEY `group_id` (`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
复制代码
Auth.zip ( 3.59 KB 下载:2999 次 )
附件 | 大小 |
---|---|
Auth.zip | 3.59 KB |
如果我把group和group_access这两个表看成角色表,那么我再建立一个资源表是否就又变会RBAC了?
http://www.thinkphp.cn/topic/36004.html
后台管理权限分配非常方便,很好!