Luke Jurgs, on 17 October 2011 - 12:34 AM, said:
I created a module called administration and I wanted to use a layout in administration/views/layouts called main. The DefaultController insisted on using the application layout, I noticed when I searched the forums a few other people had the same problem and used a work around where they set the layout in the controller and not in the module as is recommended in the documentation.
The documentation recommends setting module::layout and module::layoutPath and as CController defaults to a NULL layout it will use the module layout.
What I missed however is that the DefaultController generated by gii during module generation actually extends Controller not CCcontroller and if you generated your app from the CLI tool then the layout for Controller defaults to:
Hope this saves someone from the stupid mistake I made.
My sollution was to have DefaultController extend CController and do:
$this->layoutPath = Yii::getPathOfAlias('administration.views.layouts');
$this->layout = 'administration';
In case you're using the module generated by gii, you'll also need to do the following:
1. Copy the files from the main 'layouts' folder into your module's layouts folder (it is empty);
2. Remove from your module's views/default/index.php :
3. In AdminModule.php (or whatever your module's name) init() method:
$this->layoutPath = Yii::getPathOfAlias('admin.views.layouts');
$this->layout = 'main';
4. Extend your module's DefaultController from CController instead of Controller (as mentioned by Mr. Luke ).
5. Finally, customize your layouts by modifying the files in your module's 'layouts' folder.