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.
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.
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.
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;
}
else
return false;
}
However, while ‘main’ works, ‘column1’ or ‘column2’ and probably any other custom views within root/protected/views/layout/ directory doesn’t work