Chapter 12 - Admin module automatically uses the site theme
#1
Posted 29 October 2010 - 12:17 PM
Added the modified layout files in the module layout folder and all the other changes as the book later suggests and it still overrides them and keeps using the same theme, any idea what do I do wrong? Thanks in advance.
#2
Posted 29 October 2010 - 03:11 PM
Thanks.
#3
Posted 30 October 2010 - 07:30 AM
#4
Posted 02 November 2010 - 03:22 PM
<?php
class AdminModule extends CWebModule
{
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(
'admin.models.*',
'admin.components.*',
));
$this->layout = 'main';
}Where this 'main' refers to /protected/modules/admin/views/layouts/main.php.
#5
Posted 03 November 2010 - 12:28 PM
The system msg url is "http://localhost/trackstar/admin/sysMessage/index" and the admin page one is "http://localhost/trackstar/admin/default/index" but the admin page keeps the same links as when it was first made instead of "Back to main site" "SystemMessage" "Login" as it should be.
Every time I create a test new module it automatically takes the site layout instead of using no layout, that seems to be the problem.
#6
Posted 12 November 2010 - 11:57 AM
Did you find a solution?
#7
Posted 12 November 2010 - 01:48 PM
The solution - for me anyway - was to add a line to beforeControllerAction in AdminModule.php:
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 = 'main';
return true;
}
else
return false;
}
I think you can guess what the line is ...
Nothing worked, until I threw in that line of code.
#9
Posted 19 November 2010 - 07:49 AM
#10
Posted 04 January 2011 - 06:39 PM
class Controller extends CController
{
//public $layout='//layouts/column1';
public $layout='/layouts/column1';
public $menu=array();
public $breadcrumbs=array();
}
Then you can set the layout in the init() method of your AdminModule.php as is described in the book.
By the way, im using version 1.1.4 for the trackstar application, maybe the default $layout property in 1.1.2 is different from the one in 1.1.4. Nevertheless, this should work for all versions.
#12
Posted 28 December 2011 - 10:07 AM
I have Yii version 1.1.8 and the view file modules/admin/view/layouts/column1.php was ignored during view rendering. jacmoe's solution for adding
$controller->layout = 'main';
to AdminModule::beforeControllerAction() did help for showing the proper (classic) theme, but the that rendered only the files:
modules/admin/views/index.php and modules/admin/views/layouts/main.php.
Why bother when the content is corrent? The parsed HTML lacked the lines:
<div class="container"><div id="content">
which set a nice margin around the content and that file was supposed to be used...
The fix for me was to change the following:
1. In AdminModule::beforeControllerAction() change
$controller->layout = 'main';
to
$controller->layout = 'column1';
2. In modules/admin/views/layouts/column1.php change
<?php $this->beginContent(); ?>
(as the book suggested) to
<?php $this->beginContent('/layouts/main'); ?>Hope this helps...
Edit: Later on when column2.php comes into action,
$controller->layout = 'column1';
in AdminModule::beforeControllerAction() will have to become
$controller->layout = 'column2';
#14
Posted 02 March 2012 - 07:37 PM
If I put
$controller->layout = 'column2';in AdminModule::beforeControllerAction(), it's change the layout to site layout.
Someone can do it works?
#15
Posted 02 March 2012 - 08:21 PM
In the page 304, has a call to class SysMessage like following:
//get the latest system message to display based on the
update_time column
$sysMessage = SysMessage::model()->find(array(
'order'=>'t.update_time DESC',
));
if($sysMessage != null)
$message = $sysMessage->message;
else
$message = null;
$this->render('index',array(
'dataProvider'=>$dataProvider,
'sysMessage'=>$message,
));
But I can't render it in my view. It's diplay an error "Undefined variable: sysMessage". How can show some data in my view?
If I want create a 'test' => 'This is a test" How do it?
#16
Posted 08 May 2012 - 03:45 AM
Cálcio, on 02 March 2012 - 07:37 PM, said:
If I put
$controller->layout = 'column2';in AdminModule::beforeControllerAction(), it's change the layout to site layout.
Someone can do it works?
change first line in column2.php to this $this->beginContent('/layouts/main');
#18
Posted 07 May 2013 - 05:06 PM
jacmoe, on 12 November 2010 - 01:48 PM, said:
The solution - for me anyway - was to add a line to beforeControllerAction in AdminModule.php:
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 = 'main';
return true;
}
else
return false;
}
Great awesome Solution....manage to get this through. Thank you again, please can you put a briefly explanation what takes place when this code is inserted. Why the theme for admin is not preview until this code is inserted.
I think you can guess what the line is ...
Nothing worked, until I threw in that line of code.

Help














