我已经安装了Yii2高级应用程序,现在我想更改后端主题.我怎样才能做到这一点?有没有我需要告诉Yii2使用我的自定义主题的文件?我确定了我的主题backend/web/themes/mytheme.我刚刚更换了这段代码advanced/backend/config/main.php,但什么都没发生!
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/themes/mytheme'],
'baseUrl' => '@web/themes/mytheme',
],
],
Run Code Online (Sandbox Code Playgroud)
然后我替换了这个代码,common/config/main.php但没有改变!
ilt*_*lid 13
另一种改变Yii2主题的方法是:
在要在其中更改主题的前端或后端的Web文件夹中创建主题目录.
将主题文件夹放在主题目录中.
在前端或后端的assets文件夹中的AppAsset.php中更改$ css和$ js变量,如:
public $css = [
//'css/site.css',
'themes/theme_folder/css/font-awesome.min.css',
'themes/theme_folder/css/slicknav.css',
'themes/theme_folder/css/style.css',
'themes/theme_folder/css/responsive.css',
'themes/theme_folder/css/animate.css',
'themes/theme_folder/css/colors/red.css',
//'themes/margo/asset/css/bootstrap.min.css',
];
public $js = [
'themes/theme_folder/js/jquery.migrate.js',
'themes/theme_folder/js/modernizrr.js',
'themes/theme_folder/js/jquery.fitvids.js',
'themes/theme_folder/js/owl.carousel.min.js',
'themes/theme_folder/js/nivo-lightbox.min.js',
//'themes/theme_folder/js/jquery-2.1.4.min.js',
//'themes/theme_folder/asset/js/bootstrap.min.js'
];
Run Code Online (Sandbox Code Playgroud)不包括核心引导程序css,bootstrap js和jquery js,因为它们是由Yii2提供的核心API.我在上面评论过它们.
使用以下代码在main.php布局文件或其他网站页面中引用主题资源(css,js,图像等):
<?= Yii::getAlias('@web/themes/theme_folder') ?>/images/margo.png
Run Code Online (Sandbox Code Playgroud)没有必要在layouts-> main.php文件中包含css或js文件:)
在您的视图文件夹中创建一个视图文件夹,themes/mytheme并移动所有视图文件,如main.php所需的其他布局.
您也可以在设置基本布局backend\config\main.php一样
return [
'id' => 'app-backend',
'layout'=>'yourtheme', //your `themes/mytheme/views/` contain yourtheme.php in this case
...
Run Code Online (Sandbox Code Playgroud)
也pathmap改为
'pathMap' => ['@app/views' => '@app/themes/mytheme/views'],
Run Code Online (Sandbox Code Playgroud)