php 如何使用 AdminLTE 主题配置 Yii2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29468656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:25:36  来源:igfitidea点击:

How to configure Yii2 with AdminLTE theme

phpyii2

提问by J.K.A.

I'm new to Yii2 Framework and just configured Yii2 Advance application.

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

Now I want to configure adminLTEtheme in my Yii2 Advance application without using the Composer. Somehow Composer is not getting installed on my machine.

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

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

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

回答by vitalik_74

1) Go to https://github.com/almasaeed2010/AdminLTE/releasesand download last version.

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

2) Create folder bowerin vendorpath. And in bowercreate new folder admin-lteagain.

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

3) Extract archive from first step to /vendor/bower/admin-lte.

3) 将第一步中的存档解压缩到/vendor/bower/admin-lte.

4) Change your AppAsset(it is location in backend/assetsfolder) and add this code:

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',
    ];
}

回答by yogesh godse

Embeding admin lte theme i yii2 basic

嵌入 admin lte 主题 i yii2 basic

1) create yii project using composer

1)使用composer创建yii项目

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

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

2)now create it accessible

2)现在创建它可访问

chmod 777 -R project name

chmod 777 -R 项目名称

3) download admin lte theme by using

3)使用下载admin lte主题

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

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

copy and past all file to your basic root folder

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

4) now update composer

4)现在更新作曲家

composer update

作曲家更新

if token error then create account in git and create token in setting tab by clicking genarate new token

如果令牌错误,则在 git 中创建帐户并通过单击生成新令牌在设置选项卡中创建令牌

copy and provide it to composer

复制并提供给作曲家

5) update your web.php file in config

5) 在配置中更新你的 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) update SiteController. Php in controller folder

6) 更新 SiteController。控制器文件夹中的php

replace actionLogout with following code

用以下代码替换 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) if misconfiguration error then

7) 如果配置错误,则

update apche2

更新apche2

by using command

通过使用命令

a2enmod rewrite

a2enmod 重写

and restrart apache using

并使用重新启动apache

service apache2 restart

服务 apache2 重启

finished...........

完成的...........

best of luck

祝你好运