Home  >  Article  >  PHP Framework  >  How to reference adminlte to yii2

How to reference adminlte to yii2

藏色散人
藏色散人Original
2020-02-04 09:01:211961browse

How to reference adminlte to yii2

The access permissions of yii2 are managed by the built-in rbac component by default. You need to write the corresponding rules yourself to implement permission management, and there is no graphical interface.

Related recommendations: yii tutorial

yii2-admin visualizes the management of rbac, and you can set simple rules with just a few clicks of the mouse.

Software versions and links in this tutorial: yii2 (v2.06, using advanced templates), yii2-admin (2.0)

yii2:https://github.com/yiisoft/yii2
yii2-admin:https://github.com/mdmsoft/yii2-admin

This article does not cover custom rules and yii2-admin menus.

Assume that you have installed yii2 and created the user table in the database.

Use composer to install yii2-admin

In non-windows environment:

php composer.phar require mdmsoft/yii2-admin "~2.0"
php composer.phar update

Under Windows:

composer require mdmsoft/yii2-admin "~2.0"
composer update

The domestic network environment is complex , it may take a long time to install. If there is no response for a long time, you can terminate the command and try again.

Configuring the yii2-admin operating environment

Note: If configuring yii2-admin in the common directory takes global effect, it will cause an error in the command under the console. .

Because permission control is only applied to the frontend module, the configuration is written to the frontend directory.

Configuration file: frontend\config\main.php

return [
'modules' => [
'admin' => [
'class' => 'mdm\admin\Module',
'layout' => 'left-menu',//yii2-admin的导航菜单
]
...
],
...
'components' => [
...
'authManager' => [
'class' => 'yii\rbac\DbManager', // 使用数据库管理配置文件
]
],
'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
'site/*',//允许访问的节点,可自行添加
'admin/*',//允许所有人访问admin节点及其子节点
]
],
];

Create the corresponding database table

Enter the following command in the console:

yii migrate --migrationPath=@mdm/admin/migrations
yii migrate --migrationPath=@yii/rbac/migrations

Install to This is done.

The above is the detailed content of How to reference adminlte to yii2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn