Yeah that’s how I tried doing it in the first place but it didn’t work. I just can’t figure out why it won’t work, I haven’t configured any other options anywhere that might be conflicting with this setting.
Yeah that’s how I tried doing it in the first place but it didn’t work. I just can’t figure out why it won’t work, I haven’t configured any other options anywhere that might be conflicting with this setting.
Not sure if my copy of Yii is buggered or something but I’ve tried testing this layout issue in the Yii Blog demo and I got an unexpected result.
Basically I used Gii to create the module ‘admin’. Here is the current module arrangement in the main.php config file:
'modules'=>array(
'admin',
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'password',
// 'ipFilters'=>array(...a list of IPs...),
// 'newFileMode'=>0666,
// 'newDirMode'=>0777,
),
),
I then navigate to localhost/yii_113/demos/blog/index.php/admin and the default page is displayed, but there is no layout! There is no layout property defined in DefaultController.php but according to the docs it should render the application layout instead.
Can anyone replicate this?
take a look here
Hope that help.
daonhack - that’s not what I’m trying to do.
It worked for me
attachment is a test on my screen shot after generate module. It had layout you can see. And I followed above link that i gave you.
Yes but that’s talking about separating front-end and back-end applications in a directory structure. My initial query was regarding module config file.
Anyway the issue I have now is regarding the module layout, which doesn’t seem to be working for me.
Yes it is talking about separate front-end and back-end but WebApplicationEndBehavior.php is magic here. They will give you solution for module.
The blog demo has the $layout defined in Controller.php under components!!
@daonhack thats a decent solution if you want to have a separate config file for whatever reason.
Personally, so far in all my cases creating a admin module has been more than sufficient…
yeah that’s right. so i’d expect it to use that layout in the admin module, but for sum reason i dnt get any layout at all. were u able 2 replicate that at all?
nope not able to replicate!!!!
that controller defines the layout as “column1” therefore in the admin module you need to create a file called column1.php under layouts! I’ve not tested it but i’m 99.9% sure it will work!
public $layout='/layouts/column1';
if you want modules to have their own layout named column1.php under protected/modules/moduleName/views/layouts
public $layout='//layouts/column1';
if you want all modules to use the column1.php layout under protected/views/layouts
Cheers jayrulez, that has worked for me.
It makes sense now - by default Controller.php has a $layout property defined, which does not get overridden by the $layout property in AdminModule.php. So just comment out $layout property ion Controller.php and you can set your own layout in AdminModule.php.
What version do you use and have you modified your protected/components/Controller.php file?
I had the same problem. The default admin module controller (DefaultController.php) extends Controller and in Controllers.php you have:
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
}
AND! By default, in protected/views/layouts/column1.php you have:
<?php $this->beginContent('//layouts/main'); ?>
<div class="container">
<div id="content">
<?php echo $content; ?>
</div><!-- content -->
</div>
<?php $this->endContent(); ?>
… which forces the column1.php layout file to use main.php layout under protected/views/layouts/main.php
This is the reason the official method does not work. I’m not aware how the layouts were handled in pre 1.1.4 versions.
This is the correct method for the latest Yii: Egorka’s solution
If it doesn’t appear to work, log out and then back in.
I had the same problem… Tried everything as the topic owner… Only Snipers method worked, not mbi’s
Thx sniper anyway, I can go further in developing my application
I had this problem too, and I think I tracked down the source of the problem.
The correct method is to set:
$this->layout = '/layouts/column1';
in init() in my module, but what I didn’t realize was that although it was calling the correct file, that file in turn called the root layout.
<?php $this->beginContent('//layouts/main'); ?>
changing it to this made it work
<?php $this->beginContent('/layouts/main'); ?>
Where do we need to put this code?
This works for me, the other options seemed wrong, this makes perfect sense.
You change the column1.php and column2.php for that matter in your base app layouts directory to have only one leading forward slash.
This will stop that file from forcing the base main.php file, but instead allowing access to use the one in your module. But the base app is unaffected and continues to use the correct layout.
You then just need to set the layout path like:
public function init()
{
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'mymodule.models.*',
'mymodule.components.*',
));
// $this->layout='mylayout'; This line does nothing without changing things in other places
$this->layoutPath = Yii::getPathOfAlias('application.modules.mymodule.views.layouts');
}
And when in your module views it will access the file main.php in your module directory.
NOTE: It has to be named the same as is in column1.php in your main app.
<?php
class DefaultController extends Controller
{
public $layout='/layouts/column1'; // this will point to the modules layout directory column1.php file
...
public function actionIndex()
{
...
}
}
?>