WEB部署目录(或者子目录)
├─Auth
│ └─Auth.php Auth权限插件核心文件
│
├─Index.php DEMO控制台
├─config.php DEMO数据库配置文件
├─authInstall.php 初始化权限与角色表
├─addAuth.php 添加权限DEMO
├─listAuth.php 权限列表DEMO
├─deleteAuth.php 删除权限DEMO
├─updAuth.php 修改权限DEMO
│
├─addRole.php 添加角色DEMO
├─listRole.php 角色列表DEMO
├─deleteRole.php 删除角色DEMO
├─updRole.php 修改角色DEMO
│
├─authCheck.php 权限验证DEMO
├─getList.php 获取角色对应的权限菜单
DEMO使用说明:
1. 修改config.php 内的数据库信息
2. 运行authInstall.php 进行数据表安装
3. 运行addAuth.php 添加多几个测试的访问权限
4. 运行addRole.php 添加多几个测试的管理角色
5. 修改authCheck.php 内的$array验证信息 - 运行这个文件查看验证结果
6. 修改getList.php 内的角色id 获取角色对应的权限列表
权限表与角色表的CURD就不做详细介绍了,具体常考DEMO内的使用方法:
DEMO公共统一参数:
权限验证过滤:
- # 引入Auth类
- include './Auth/Auth.php';
- # 引入配置文件
- $config = include 'config.php';
- $str = new Auth();
- $str->set('dbName',$config['dbName']); // 数据库名
- $str->set('dbUser',$config['dbUser']); // 账号
- $str->set('dbPwd',$config['dbPwd']); // 密码
- $str->set('tablePrefix',$config['tablePrefix']); // 表前缀
- $info = $str->M(); // 获得PDO实例
- /* 使用方法: 管理员表 增加一个角色ID字段 用于管理员关联对应的角色 超级管理员角色ID为0*/
- # 引入Auth类
- include './Auth/Auth.php';
- # 引入配置文件
- $config = include 'config.php';
- $str = new Auth();
- $str->set('dbName',$config['dbName']); // 数据库名
- $str->set('dbUser',$config['dbUser']); // 账号
- $str->set('dbPwd',$config['dbPwd']); // 密码
- $str->set('tablePrefix',$config['tablePrefix']); // 表前缀
- $info = $str->M(); // 获得PDO实例
- $array = array(
- 0 => 1, // 管理员对应的角色ID - 0为超级管理员
- 1 => 'Index', // 当前操作的控制器
- 2 => 'Head', // 当前的才操作方法
- 3 => array( // 默认不过滤的访问权限
- 'Index/Left',
- 'Index/Index',
- 'Index/Footer'
- )
- );
- # 执行权限过滤
- if ($info->authCheck($array)) {
- die( '权限核验通过' );
- }
- die( '权限核验不通过' );
友情提示:垃圾评论一律封号...