Yii Framework Forum: Chapter 12 - Admin module automatically uses the site theme - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 12 - Admin module automatically uses the site theme

#1 User is offline   JovanS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 05-October 10

Posted 29 October 2010 - 12:17 PM

Just created a new admin module few times and it keeps using the newlayout theme we made for the rest of the site instead of showing it without any layout.

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.
0

#2 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 29 October 2010 - 03:11 PM

Could you confirm the version of the Yii framework you are using when having this issue? 1.1.2?, 1.1.3?, 1.1.4?

Thanks.
0

#3 User is offline   JovanS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 05-October 10

Posted 30 October 2010 - 07:30 AM

1.1.2 and as far as I know I did everything by the book, anything else to check for?
0

#4 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 02 November 2010 - 03:22 PM

Does your AdminModule specify the layout to use?..specifcally $this->layout = 'main'?

<?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.
0

#5 User is offline   JovanS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 05-October 10

Posted 03 November 2010 - 12:28 PM

Yeah, and I followed the rest of the chapter and did all the other changes and everything else works good, the system message page uses the correct blue layout and all the rest works except the first admin page which doesn't take the changes somehow.

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.
0

#6 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 12 November 2010 - 11:57 AM

I have the same probleme!
Did you find a solution?
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#7 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 12 November 2010 - 01:48 PM

Had the same problem.

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.
"Less noise - more signal"
2

#8 User is offline   leogsouza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 22-May 09
  • Location:São Paulo, Brazil

Posted 15 November 2010 - 05:49 PM

I had the same problem and this solution work for me thanks!!
0

#9 User is offline   JovanS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 05-October 10

Posted 19 November 2010 - 07:49 AM

yeah, sorry for the late response but it did work for me too, thanks, could put it as solved I guess.
0

#10 User is offline   dito 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 13-October 10
  • Location:Zurich

Posted 04 January 2011 - 06:39 PM

I had the same problem, but after trying jacmoes solution, the column1.php layout was not rendered anymore. In the Controller class (the one in the components folder), I made a simple change to the default $layout property as follows:

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.
1

#11 User is offline   samba 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 11

Posted 28 November 2011 - 10:41 PM

jacmoe thank you. your solution worked for me also =))
0

#12 User is offline   yasen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 29-October 11
  • Location:Sofia, Bulgaria

Posted 28 December 2011 - 10:07 AM

Hello,

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';

1

#13 User is offline   sbern 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-January 12

Posted 28 February 2012 - 05:47 AM

Thank you Yasen,

works for me on Yii 1.1.9.
0

#14 User is offline   Cálcio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 18-January 11
  • Location:Niterói - RJ - Brazil

Posted 02 March 2012 - 07:37 PM

Hi. I cannot display the colum2 in the System Message.

If I put
$controller->layout = 'column2';
in AdminModule::beforeControllerAction(), it's change the layout to site layout.

Someone can do it works?
0

#15 User is offline   Cálcio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 18-January 11
  • Location:Niterói - RJ - Brazil

Posted 02 March 2012 - 08:21 PM

Another error.

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?
0

#16 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 08-May 12

Posted 08 May 2012 - 03:45 AM

View PostCálcio, on 02 March 2012 - 07:37 PM, said:

Hi. I cannot display the colum2 in the System Message.

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');
0

#17 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 08-May 12

Posted 11 May 2012 - 02:47 AM

View Postnakarin, on 08 May 2012 - 03:45 AM, said:

change first line in column2.php to this $this->beginContent('/layouts/main');


and DefaultController.php

<?php

class DefaultController extends Controller
{

public function actionIndex()
{
$this->layout='/layouts/column1';
$this->render('index');
}
}

?>
0

#18 User is offline   Joemaxwell 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 13-February 13
  • Location:Fiji Via Melbourne

Posted 07 May 2013 - 05:06 PM

View Postjacmoe, on 12 November 2010 - 01:48 PM, said:

Had the same problem.

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.

0

#19 User is offline   StreetCoder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 13-April 13

Posted 23 October 2013 - 01:53 AM

Hi Everyone,

After reading this full thread, I solved my problem. What I did, am writing following:
DefaultController.php :

class DefaultController extends Controller
{
        public $layout='column1';

	public function actionIndex()
	{
        //$this->layout='/layouts/main';
        $this->render('index');
	}
}


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';
    }

    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
            return true;
        }
        else
            return false;
    }
}


writing the
public $layout='column1';
in the default controller will help to use different coloumn in the admin theme. If you use
$controller->layout = 'main';
in the beforeControllerAction in AdminModule.php will fix you to use only single layout. If you introduce new controller in admin module, just write this line
public $layout='column1';
at top of the controller as like DefaultController.php

Thanks
0

#20 User is offline   cof 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 24-December 13

Posted 24 December 2013 - 11:19 AM

this is what worked for me (Yii ver 1.1.14)

AdminModule.php

$this->layoutPath = Yii::getPathOfAlias('admin.views.layouts');
$this->layout = 'main';


<?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->layoutPath = Yii::getPathOfAlias('admin.views.layouts');
              $this->layout = 'main';
	}

	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
                        
			return true;
		}
		else
			return false;
	}
}


DefaultController.php

public $layout = 'column1';

<?php

class DefaultController extends Controller
{
        public $layout = 'column1';
	public function actionIndex()
	{
		$this->render('index');
	}
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users