Yii-auth权限使用 [ 未指定版本 ]
1.下载authbooster 用于权限控制
http://www.yiiframework.com/extension/authbooster
2.在protected文件夹下新建modules/
把下载的扩展放到moudules下
3.在配置文件main.php
return array(
...
'language' => 'zh',
...
),
'modules'=>array(
//-----------------
'auth'=>array(
'userClass' => 'User', // the name of the user model class.
'userIdColumn' => 'id', // the name of the user id column.
'userNameColumn' => 'username', // the name of the user name column.
'defaultLayout' => 'application.admin.views.layouts.column2',
),
),
'components' => array(
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap',
'responsiveCss' => true,
),
//auth-------------
'authManager' => array(
'class' => 'CDbAuthManager',
'connectionID' => 'db',
'itemTable' => '{{authitem}}',//数据库
'itemChildTable' => '{{authitemchild}}', //数据库
'assignmentTable' => '{{authassignment}}',//数据库
'behaviors' => array(
'auth' => array(
'class' => 'auth.components.AuthBehavior',
),
),
),
//--------------------
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => true,
'class' => 'auth.components.AuthWebUser',
// users with full access
'admins' => array('admin'),
),
)
//'params'=>CMap::mergeArray(require($frontend.'/config/params.php'),require($backend.'/config/params.php')),
);
4.新建数据库
CREATE TABLE IF NOT EXISTS `pre_authassignment` (
`itemname` varchar(64) NOT NULL,
`userid` varchar(64) NOT NULL,
`bizrule` text,
`data` text,
PRIMARY KEY (`itemname`,`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='授权表';
CREATE TABLE IF NOT EXISTS `pre_authitem` (
`name` varchar(64) NOT NULL,
`type` int(11) NOT NULL,
`description` text,
`bizrule` text,
`data` text,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `pre_authitemchild` (
`parent` varchar(64) NOT NULL,
`child` varchar(64) NOT NULL,
PRIMARY KEY (`parent`,`child`),
KEY `child` (`child`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `pre_authassignment`
ADD CONSTRAINT `pre_authassignment_ibfk_1` FOREIGN KEY (`itemname`) REFERENCES `pre_authitem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `pre_authitemchild`
ADD CONSTRAINT `pre_authitemchild_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `pre_authitem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `pre_authitemchild_ibfk_2` FOREIGN KEY (`child`) REFERENCES `pre_authitem` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;
5.在配置文件main.php
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=*******',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
6.在浏览器打开
http://localhost/*********/admin.php?r=auth/
咔咔咔 北京
注册时间:2013-08-04
最后登录:2020-05-27
在线时长:26小时37分
最后登录:2020-05-27
在线时长:26小时37分
- 粉丝35
- 金钱535
- 威望165
- 积分2445
共 1 条评论
这样配制后一直报别名 "bootstrap.widgets.TbGridView" 是无效的. 请确定它指向一个已存在的目录或文件.