一、安装
https://github.com/mdmsoft/yii2-admin
下载安装:
composer require mdmsoft/yii2-admin "2.x-dev"
二、配置
'components' => [
···
"authManager" => [
"class" => 'yii\rbac\DbManager', //这里记得用单引号而不是双引号
"defaultRoles" => ["guest"],
],
],
'modules' => [
'admin' => [
'class' => 'mdm\admin\Module',
'layout' => 'left-menu'
]
],
//在配置文件中用 as access 对整个项目规则限制
'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
"*"//配置完后取消这个*
//这里是允许访问的action
//controller/action
]
三、创建数据库
php yii migrate --migrationPath=@mdm/admin/migrations
上面的命令会在数据库创建user表和menu表。
rbac相关表:
php yii migrate --migrationPath=@yii/rbac/migrations
或者执行
<project>/vendor/yiisoft/yii2/rbac/migrations/schema-mysql.sql里的sql语句
四、地址栏加上admin访问即可出现