layout/layoutPath for module

According to the documentation, if no layout file is specified for a module, the parent’s layout file or the application’s layout file will be used if available. However, i’ve just generated a new webapp and generated a few modules and when i access the module in the browser, it’s not rendered iside the application’s layout. There was no layout specified for the module so i expected it to use the application’s layout file. Isn’t that so? Was there a change introduced that has changed that functionality?

I did the same thing as you did. Generated a new webapp and generated an admin module.

When accessing the module in my browser it nicely renders inside the app’s layout.

So from this point, no problems here.

But what I wanted is another layout for my module then the app’s layout.

So I have created a new layout and placed it under /protected/modules/admin/views/layouts/main.php

I would expect that the module now would render in my new layout but it still renders in the application layout.

I thought that I would have to change the layout path in AdminModule.php in the init method by placing $this->setLayOutPath( …path-to… /protected/modules/admin/views/layouts ), but that doesn’t seem to effect the layoutPath.

By setting $this->layout=‘main’ in AdminModule class solved my issue.

The layout property of CWebModule is null by default which results in using the application’s layout (or parent module layout).

My issue is that it’s not using the application’s layout.

I was also able to include a module specific layout by specifying it in the controller class but thats not the proper way to do it

I had exactly the same problem. The trick is to specify the application layout you want to use in the module using a path alias, e.g. "application.views.layouts.admin" will use the applications admin layout.

Hope that helps.

Not sure if any of you has resolved this already, but I had the same problem and got here, with no luck, then solved it myself that I think might worth mention it here.

I used Gii for code generation, I found out that the controllers under the module have this property:

public $layout=‘column2’;

simply comment out the above line will makes the controller using the default parent layouot.

But what if you want to change the layout? I have a module which uses main and column2…

And want to keep the same design I can hardcode it only for themes… but then somebody who does not use themes cannot use it :P

Why this does not work?

$layout_dir = YiiBase::getPathOfAlias($this->layoutDir).DIRECTORY_SEPARATOR;            


Having the same problem, by default my module should use /protected/views/layout/main.php

without having me defining it in the module

a work around is setting the main view in MyModule.php as bellow

	public function beforeControllerAction($controller, $action)


		if(parent::beforeControllerAction($controller, $action))


			// this method is called before any module controller action is performed

			// you may place customized code here

			$controller->layout = 'application.views.layouts.main'; // path to your view 


			return true;



			return false;


However, while ‘main’ works, ‘column1’ or ‘column2’ and probably any other custom views within root/protected/views/layout/ directory doesn’t work