yii2-adminlte-asset / yii2-admin 安装配置

1.承接上一篇,安装一个靓的模板(yii2-adminlte-asset)AdminLTE 。以及一个user图形化管理界面(yii2-admin)
2. 首先安装yii2-adminlte-asset ,同样是采用composer 安装,注意得到yii2的安装目录,默认的就是advanced

E:\Program Files\phpStudy\WWW\yii2\advanced>composer require dmstr/yii2-adminlte-asset "2.*"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing rmrevin/yii2-fontawesome (2.15.1)
    Loading from cache
  - Installing almasaeed2010/adminlte (v2.3.5)
    Loading from cache
  - Installing cebe/yii2-gravatar (1.1)
    Loading from cache
  - Installing dmstr/yii2-adminlte-asset (2.3.1)
    Loading from cache
Writing lock file
Generating autoload files
E:\Program Files\phpStudy\WWW\yii2\advanced>

2.1 网上有方法是直接配置相关文件,我这里的方法暴力点直接copy文件覆盖了默认的view配置文件

覆盖掉yii自带的layout.
把vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app目录下的layouts和site拷贝 
覆盖掉backend/views/目录下的lauouts和site对应的文件

2.2 看看效果

3 . 安装yii2-admin , 实现RBAC 权限管理(角色的访问控制(Role-Based Access Control))- 在 advanced 版本下实现

D:\phpStudy\WWW\yii2\advanced>php composer.phar require mdmsoft/yii2-admin "~2.0"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing mdmsoft/yii2-admin (2.6)
    Loading from cache
Writing lock file
Generating autoload files

4. 配置(配置文件:frontend\config\main.php),这边直接贴出来已经完成配置的,要用的话可以直接copy去用。【幻风寒影 2016-07-11 14:43:10】

<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);
return [
    'modules' => [
        'admin' => [
            'class' => 'mdm\admin\Module',
            'layout' => 'left-menu',
        ]
    ],
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'authManager' => [
            'class' => 'yii\rbac\DbManager', // 使用数据库管理配置文件
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        /*
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        */
    ],
    'as access' => [
        'class' => 'mdm\admin\components\AccessControl',
        'allowActions' => [
            'site/*', //sites for access
            'admin/*', // allow everyone to access 'admin'
        ]
    ],
    'params' => $params,
];

5.执行如下命令创建数据库

E:\Program Files\phpStudy\WWW\yii2\advanced>yii migrate --migrationPath=@mdm/admin/migrations
Yii Migration Tool (based on Yii v2.0.8)
Total 2 new migrations to be applied:
        m140602_111327_create_menu_table
        m160312_050000_create_user
Apply the above migrations? (yes|no) [no]:yes
*** applying m140602_111327_create_menu_table
    > create table {{%menu}} ... done (time: 0.121s)
*** applied m140602_111327_create_menu_table (time: 0.228s)
*** applying m160312_050000_create_user
*** applied m160312_050000_create_user (time: 0.030s)
2 migrations were applied.
Migrated up successfully.
E:\Program Files\phpStudy\WWW\yii2\advanced>

6. 配置(yii2\advanced\common\config\main.php)

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
        ],
    ],
];

6.1 然后创建如下表格

E:\Program Files\phpStudy\WWW\yii2\advanced>yii migrate --migrationPath=@yii/rbac/migrations
Yii Migration Tool (based on Yii v2.0.8)
Total 1 new migration to be applied:
        m140506_102106_rbac_init
Apply the above migration? (yes|no) [no]:yes
*** applying m140506_102106_rbac_init
    > create table {{%auth_rule}} ... done (time: 0.093s)
    > create table {{%auth_item}} ... done (time: 0.072s)
    > create index idx-auth_item-type on {{%auth_item}} (type) ... done (time: 0.118s)
    > create table {{%auth_item_child}} ... done (time: 0.109s)
    > create table {{%auth_assignment}} ... done (time: 0.072s)
*** applied m140506_102106_rbac_init (time: 0.501s)
1 migration was applied.
Migrated up successfully.
E:\Program Files\phpStudy\WWW\yii2\advanced>

7.至此安装完成,访问验证下

http://localhost/yii2/advanced/frontend/web/index.php?r=admin

 

posted @ 2016-07-11 14:48  乾坤颠倒  阅读(13851)  评论(2编辑  收藏  举报