如何使用 AdminLTE 主题配置 Yii2
How to configure Yii2 with AdminLTE theme
我是 Yii2 Framework 的新手,刚刚配置了 Yii2 Advance 应用程序。
现在我想在不使用 Composer 的情况下在我的 Yii2 Advance 应用程序中配置 adminLTE 主题。不知何故,我的机器上没有安装 Composer。
1) 转到 https://github.com/almasaeed2010/AdminLTE/releases 并下载最新版本。
2) 在 vendor
路径中创建文件夹 bower
。并在 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',
];
}
嵌入 admin lte 主题 i yii2 basic
1) 使用 composer 创建 yii 项目
须藤杜
光盘 /var/www/html
作曲家创建项目 yiisoft/yii2-app-basic 基本 2.0.4
2) 现在创建它可访问
chmod 777 -R 项目名称
3) 使用
下载 admin lte 主题
git 克隆 https://github.com/bmsrox/baseapp-yii2basic-adminlte.git
将所有文件复制并粘贴到您的基本根文件夹
4) 现在更新作曲家
作曲家更新
如果令牌错误,则在 git 中创建帐户并通过单击生成新令牌
在设置选项卡中创建令牌
复制并提供给作曲家
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) 更新站点控制器。 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) 如果配置错误则
更新 apche2
通过使用命令
a2enmod 重写
并使用
重新启动apache
服务 apache2 重启
完成......
祝你好运
我是 Yii2 Framework 的新手,刚刚配置了 Yii2 Advance 应用程序。
现在我想在不使用 Composer 的情况下在我的 Yii2 Advance 应用程序中配置 adminLTE 主题。不知何故,我的机器上没有安装 Composer。
1) 转到 https://github.com/almasaeed2010/AdminLTE/releases 并下载最新版本。
2) 在 vendor
路径中创建文件夹 bower
。并在 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',
];
}
嵌入 admin lte 主题 i yii2 basic
1) 使用 composer 创建 yii 项目
须藤杜 光盘 /var/www/html 作曲家创建项目 yiisoft/yii2-app-basic 基本 2.0.4
2) 现在创建它可访问
chmod 777 -R 项目名称
3) 使用
下载 admin lte 主题git 克隆 https://github.com/bmsrox/baseapp-yii2basic-adminlte.git
将所有文件复制并粘贴到您的基本根文件夹
4) 现在更新作曲家
作曲家更新
如果令牌错误,则在 git 中创建帐户并通过单击生成新令牌
在设置选项卡中创建令牌复制并提供给作曲家
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) 更新站点控制器。 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) 如果配置错误则
更新 apche2
通过使用命令
a2enmod 重写
并使用
重新启动apache服务 apache2 重启
完成......
祝你好运