In module I do not have a Controller class in Components whereas in protected/components I have One which defines the layout of all Controllers to
public $layout='//layouts/column1';
Then, I think that when I request an Admin action,
-1- AdminModule (child of CWebModule) is called. In this we set the targeted layout
$this->layout='/layouts/column2-admin';
-2- After that I suppose that (In my case) DefaultController of Admi module is called. But by doing this I use the Controller Class of protected/components which defines another layout …
Then How does it stand. For my point of view defining something in AdminModule (child of CWebModule) is useless
As a test, try to set the layout directly in in the action of the module, and check if it works (just for be sure that this call to the layout is correct).
If the problem is your master class, you can always use a new one for admin module.
in DefaultController (or in whatever controllers in Admin Module), then http://localhost/webapp/index.php?r=admin/default works fine and I obtain the right layouts located in my modules/admin/views/layouts…
For sure by doing this I override the Controller base class (which sets layout).
But I do not like this solution (I hate this solution). I can’t imagine setting all my Admin’s controllers by this way.
I read a lot of docs that indicates to set up this layout in the AdminModule (child of CWebModule) But for me, Whatever I write in this class (I mean write concerning layout) nothing is taken into account.
I precise also, that I just begin my webapp, and my module, then I think that I’m not so far from the right way of doing the things (because no time for bug introduction )
I created an admin module and I was wrestling with this same problem for the longest. The module was using the main application layout even though I specified for it to use a different layout in AdminModule(as shown in the Yii book).
These are the steps I did to make it work.
From protected/components, I copied Controller to protected/modules/admin/components.
From protected/views/layouts, I copied column1, column2 and main (I just copied and edited main for the admin module, although you can rename it to whatever as long as you reference it in AdminModule) to protected/modules/admin/views/layouts.
In the init method of AdminModule, I specified the copied main layout to be used.
$this->layout = 'main';
In the copied column1 and column2, I removed the ‘//layouts/main’ from the call to beginContent.
<?php $this->beginContent(); ?>
Finally, in the copied Controller, I specified the layout as column1 (or column2), without //layouts.
public $layout='column1';
Y así funcionó. That’s how I got it to work. Perhaps that will help some of you out there.
thanks, that worked for me, too. However, you can make it a bit easier. You don’t necessarily have to copy the Controller.php. Instead, you can use the following in AdminModule.php:
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
$controller->layout = 'column2';
// this method is called before any module controller action is performed
// you may place customized code here
return true;
}
else
return false;
}
I have admin module which already set $controller->layout = ‘adminmain’; in AdminModule.php public function beforeControllerAction($controller, $action)
it apply ‘adminmain’ layout to all my admin controllers, however, I want my some of other admin controllers to use layout ‘column2’ for example, how to deal with that?
this is a bit late reply considering the age of this post. But I have been struggling with the exact same problem and found the following solution, maybe it is useful to someone.