Yii Framework Forum: Switch Layout Dynamically - Yii Framework Forum

Jump to content

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

Switch Layout Dynamically ... is this a bug? Rate Topic: -----

#1 User is offline   DerekC 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 09-December 09
  • Location:Europe

Posted 07 February 2013 - 10:29 AM

Running: yii-1.1.10.r3566

I would expect CController->layout to be passed to any render() command, but it seems this is not the case.

I have the following:

class ActionController extends Controller {
	public $layout='column2';
...
	public function actionView() {
		$this->layout = 'column1'; // <-- this has no effect
...
		$this->render( 'view', array(
			'layout'=>'column1', // <-- this has no effect (this would actually create a $layout variable, but I was just trying my luck... ;)
			'model'=>$model,
		) );
	}


and in the view

<?php
$this->layout='column1'; // <-- [b]only this[/b] forces the layout to be changed



My expectation is that layout should be changeable by the CController - it is public after all!!
Question: is this a bug?
0

#2 User is offline   seenivasan 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 599
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 07 February 2013 - 10:55 AM

Dear Friend

It should be
public function actionIndex()
	{       $this->layout="//layouts/column1";
		$dataProvider=new CActiveDataProvider('Game');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}



or just do the following in view.
$this->layout="//layouts/column1";


no need to pass as data to view file.
Regards.
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