如何使用AdminLTE主题配置Yii2 [关闭]

问题描述 投票:4回答:2

我是Yii2 Framework的新手,刚刚配置了Yii2 Advance应用程序。

现在我想在不使用Composer的情况下在我的Yii2 Advance应用程序中配置adminLTE主题。不知怎的,Composer没有安装在我的机器上。

参考:http://www.yiiframework.com/wiki/729/tutorial-about-how-to-integrate-yii2-with-fantastic-theme-adminlte/

php yii2
2个回答
15
投票

1)转到https://github.com/almasaeed2010/AdminLTE/releases并下载最新版本。

2)在bower路径中创建文件夹vendor。并在bower再次创建新的文件夹admin-lte

3)从第一步中提取存档到/vendor/bower/admin-lte

4)更改您的AppAsset(它位于backend/assets文件夹中)并添加以下代码:

class AppAsset extends AssetBundle
{
    public $sourcePath = '@bower/';
    public $css = ['admin-lte/dist/css/AdminLTE.css'];
    public $js = ['admin-lte/dist/js/AdminLTE/app.js'];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
        'yii\bootstrap\BootstrapPluginAsset',
    ];
}

0
投票

在yii2 basic中嵌入adminlte主题

1)使用composer创建yii项目

sudo du cd / var / www / html composer create-project yiisoft / yii2-app-basic basic 2.0.4

2)现在创建它可访问

chmod 777 -R项目名称

3)使用下载admin lte主题

git clone https://github.com/bmsrox/baseapp-yii2basic-adminlte.git

将所有文件复制并粘贴到基本根文件夹中

4)现在更新作曲家

作曲家更新

如果是令牌错误,则在git中创建帐户,并通过单击genarate new token在设置选项卡中创建令牌

复制并提供给作曲家

5)在config中更新你的web.php文件

<?php

$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'layout'=>'column2',
    'layoutPath'=>'@app/themes/adminLTE/layouts',
    'components' => [

     'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                ''=>'site/index',
                '<action:(index|login|logout)>'=>'site/<action>',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>'
            ],
        ],

         'view' => [
            'theme' => [
                'pathMap' => ['@app/views' => '@app/themes/adminLTE'],
                'baseUrl' => '@web/../themes/adminLTE',
            ],
        ],

        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'n0VkMX1RmIa_ovJmwR3Gn_hdZyQ7SyKe',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    //$config['modules']['gii'] = 'yii\gii\Module';
    $config['modules']['gii'] = [
            'class' => 'yii\gii\Module',
            'generators' => [ //here
                'crud' => [ // generator name
                    'class' => 'yii\gii\generators\crud\Generator', // generator class
                    'templates' => [ //setting for out templates
                        'custom' => '@vendor/bmsrox/yii-adminlte-crud-template', // template name => path to template
                    ]
                ]
            ],
        ];
}

return $config;

6)更新SiteController。 Php在控制器文件夹中

用以下代码替换actionLogout

public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->redirect(Yii::$app->user->loginUrl);
    }

    public function beforeAction($action)
    {
        if (parent::beforeAction($action)) {
            // change layout for error action
            if ($action->id=='login')
                 $this->layout = 'login';
            return true;
        } else {
            return false;
        }
    }

7)如果错误配置错误则

更新apache2

通过使用命令

a2enmod重写

并使用重启apache

service apache2 restart

完成...........

祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.