phplayoutyiiyii-modules

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?


Solution

  • well use this

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