Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default view path in Yii2?

Tags:

php

yii2

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();
    }

}

and added in config.php

'view' => [
        'class' => 'frontend\components\NewsView',

but it doesn't work too.

What should I do?

like image 735
Serhat Avatar asked Nov 19 '14 23:11

Serhat


1 Answers

You can redefine getViewPath method at your base controller. Like

public function getViewPath()
{
    return Yii::getAlias('@frontend/views/newview');
}
like image 91
Kirill Freiman Avatar answered Oct 16 '22 21:10

Kirill Freiman