kipzes
kipzes

Reputation: 714

Inherit layout from parent module in submodules Yii

In my Yii application I want to create a admin module. So far I've created a module called 'admin' and created a login page that uses the layout: layout.php. Inside the admin module I want to add all my submodules. So I've created the submodule 'dashboard' at first. Now I want all my submodules to have the layout admin.php.

How do I get this working?

My application structure looks like this:

application
    modules
        admin
            assets
            controllers
            views
                default
                    - index.php
                    - login.php
                layouts
                    - admin.php
                    - login.php
            modules
                dashboard
                    assets
                    controllers
                    views

I've set the layout for the login page like this(inside the defaultController from the admin module):

    $this->layout = "login";
    $this->pageTitle = "Beheersysteem";
    $this->render('login', array('model' => $model));

Inside the init() function in the AdminModule.php file I've also set the layout like this:

public function init()
{
    $this->setImport(array(
        'admin.models.*',
        'admin.components.*',
    ));

    $this->layout = 'admin';
}

But how do I get this admin layout working in my submodules?

Upvotes: 1

Views: 688

Answers (3)

Suryana Suryana
Suryana Suryana

Reputation: 1

this example my module is corporate and I use jeasyui as theme:

/**
 * corporate module definition class
 */
class Module extends \yii\base\Module
{
    /**
     * {@inheritdoc}
     */
    public $controllerNamespace = 'backend\modules\corporate\controllers';

    /**
     * {@inheritdoc}
     */
    public function init()
    {
        parent::init();

        $themeViewPath = '/themes/jeasyui/views';
        $this->viewPath = dirname($this->viewPath) . $themeViewPath;
        $newPathMap = array_merge(array('@app/modules/'.$this->id. $themeViewPath), $this->view->theme->pathMap['@app/views']);
        $this->view->theme->pathMap['@app/views'] = $newPathMap;
    }
}

Upvotes: 0

kipzes
kipzes

Reputation: 714

Move the layout file to the application layouts folder

application
    views
        layouts

Add the following line of code to the controller of your module

public $layout = '//layouts/admin';

Upvotes: 0

Sushant
Sushant

Reputation: 1414

well use this

$this->layout = 'application.modules.admin.views.layouts.admin';

Upvotes: 2

Related Questions