Parent Module layout path


I have the following structure:













As you can see i am using modules and child modules. Now this works fine. I would like to point your attention to one of the features available within Yii framework, The layouts.

At this time all i did was to add main.php to the admin/views/layouts/ directory and i hoped that all my child modules controllers will use that layout file.

Now when i create and add the main.php layout file to the admin/modules/core/views/layouts directory it feeds from that directory as it should, How ever when i remove that file it won’t print any layout even though the layout exists in the parent module which is the admin module.

Now When i ever i add the same layout file into the directory Protected/views/layouts with the name main.php as the default name used by the framework it does work and uses that layout from that path (Protected/views/layouts/main.php).

Now according to the Documentation and i quote


“the layout that is shared by the controllers inside this module. If a controller has explicitly declared its own layout, this property will be ignored. If this is null (default), the application’s layout or the parent module’s layout (if available) will be used. If this is false, then no layout will be used.”

Notice the highlighted text that explains that if the property left as it is by default which is Null then it will try to locate it through the currently used module layout directory (admin/modules/core/views/layouts/main.php) Other wise it will try to look for the layout under the applications layouts (Protected/views/layouts/main.php) If both fails (I assume) then it will try to look for under it’s parent module layout path (modules/admin/views/layouts/main.php). The first two options works



If i remove both of them the third one which should work as well if the first two fails, Fails as well.

I was wondering if anyone encountered this issue or maybe this is a bug and needs reporting.

Any help will be appreciated.


Maybe you have defined ‘layout’ variable inside CoreModule.php?

see this post it looks related:

I don’t know if this will help anyone, but I did an ugly hack to set my layout inside a controller inside a submodule.

I set the $layout like this on the controller:

public $layout='//../modules/mymodule/views/layouts/column2';

This made my controller use the layout from it’s parent module (not the root layout and not the current).

Hope this helps.

Simple [but not a proper way] to do this

  1. First create class which will extend to Controller class of yii like

class MyController extends Controller {

public $layout = 'application.modules.admin.views.layouts.main';


  1. then extends each controller of admin modules & it’s child modules to these class,

So u will have the one layout for all admin panel.