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:
public $layout='//layouts/column1';
Hope this saves someone from the stupid mistake I made.
My sollution was to have DefaultController extend CController and do:
Sorry to jump on an old thread, and it’s really good advice, but I’d like to add one thing, in case anyuone’s in the situation I’m in where I need a method located in the Controller class. Instead of extending the default controller from CController, you can still extend from Controller (as that extends from CController anyway), only you’ll need to remove the following line from the Controller class;
[PHP]public $layout=’//layouts/column1’;[/PHP]
as this is overwriting the value set in the init() method for the module controller
To have a personalized layout for the module you also can create a components/Controller class in your module and extending it from CController class.
It is not a good idea to overwrite the layout property in the application Controller class because these changes will apply for the entire application, not only for the module.
Defining a Controller class for a specific module you will be able to customize the module’s Controller class, without changing the entire application behaviour.