G
G
Gleb2015-08-06 11:44:15
Yii
Gleb, 2015-08-06 11:44:15

How to use theming in modules?

Colleagues, good afternoon.
I'm switching to yii2. There was a question with theming in modules.
The desire is to have a themes folder, store various templates in it, have a modules folder in the templates and, according to the names of modules and controllers, views.
I collect everything manually, without using gii.
Config:

'view' => [
            'theme' => [
                'pathMap' => ['@app/views' => '@webroot/themes/basic/views'],
                'baseUrl' => '@web/themes/basic',
            ],
        ],

Directory structure:
0opWQzEC-JCudRUPSLEeMkptDNqA87fX709oo8lT
Default controller in the site module:
namespace app\modules\site\controllers;

use Yii;
use app\models\Post;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

class DefaultController extends Controller
{
    
    public function init()
    {
        parent::init();
    }
    
    public function actionIndex()
    {
        $this->render('index', []);
    }
    
}

And here is the error. I understand what's wrong, but I can't fix it.
Invalid Parameter - yii\base\InvalidParamException
The view file does not exist: /var/www/yii2/modules/site/views/default/index.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2015-08-06
@sanchezzzhak

As an option:

<?php

namespace app\modules\dashboard;

class Module extends \yii\base\Module
{
    public $controllerNamespace = 'app\modules\dashboard\controllers';

    public function init()
    {
        parent::init();
        $theme = ''; // Yii::$app-> ... как-то тут можно вытащить название темы которая сейчас установлена
        $this->viewPath = '@app/themes/'.$theme.'/modules/'. $this->id ;
       
        // custom initialization code goes here
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question