如何更改 Yii2 中的默认视图路径? [英] How to change default view path in Yii2?
本文介绍了如何更改 Yii2 中的默认视图路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在高级 yii2 中做多主题.我为此尝试了很多方法,但它不起作用我无法理解.首先,我将其添加到frontend/config/main.php"中;
I am trying to do multi theme in advanced-yii2. I tried a lot of way for this but it doesn't work I can't understand. Firstly, I added this to "frontend/config/main.php";
'view' => [
'theme' => [
'pathMap' => [
'@app/views' => [
'@webroot/themes/demo/views',
]
],
],
],
它不起作用,然后我尝试为前端创建一个新的视图类,例如:
and it doesn't work, then I tried to creating a new view class for frontend, for example:
namespace frontend\components;
class NewsView extends \yii\web\View {
function init() {
\Yii::$app->view->viewPath = '@webroot/themes';
parent::init();
}
}
并在 config.php 中添加
and added in config.php
'view' => [
'class' => 'frontend\components\NewsView',
但它也不起作用.
我该怎么办?
推荐答案
您可以在基本控制器上重新定义 getViewPath 方法.喜欢
You can redefine getViewPath method at your base controller. Like
public function getViewPath()
{
return Yii::getAlias('@frontend/views/newview');
}
这篇关于如何更改 Yii2 中的默认视图路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文