Yii Framework Forum: When Was The Layouts Is Being Called - Yii Framework Forum

Jump to content

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

When Was The Layouts Is Being Called Rate Topic: -----

#1 User is offline   ezekel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 154
  • Joined: 03-May 14

Posted 04 May 2014 - 07:23 AM

Hi,

Yii people, this is the first time that i use Yii.And I am still studying on this,...I already installed the yii framework,and i also launched the welcome page...My question is when was the Layouts is being called in the controller ?, I tried to look at in the SiteController.php,I did not see the Views/layouts is being called...

can you help me please enlighten my mind.


Thank you in advance.
0

#2 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 04 May 2014 - 12:00 PM

View Postezekel, on 04 May 2014 - 07:23 AM, said:

Hi,

Yii people, this is the first time that i use Yii.And I am still studying on this,...I already installed the yii framework,and i also launched the welcome page...My question is when was the Layouts is being called in the controller ?, I tried to look at in the SiteController.php,I did not see the Views/layouts is being called...

can you help me please enlighten my mind.

Thank you in advance.

Layouts are called in the internals of $this->render()
Do, or do not. There is no 'try.' Jedi Master Yoda
0

#3 User is offline   ezekel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 154
  • Joined: 03-May 14

Posted 05 May 2014 - 12:52 PM

View Postjkofsky, on 04 May 2014 - 12:00 PM, said:

Layouts are called in the internals of $this->render()



Hi, You mean in the Sitcontroller.php /

public function actionIndex()
	{
		// renders the view file 'protected/views/site/index.php'
		// using the default layout 'protected/views/layouts/main.php'
		$this->render('index');
	}

0

#4 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 11 May 2014 - 10:53 PM

View Postezekel, on 05 May 2014 - 12:52 PM, said:

Hi, You mean in the Sitcontroller.php /

public function actionIndex()
	{
		// renders the view file 'protected/views/site/index.php'
		// using the default layout 'protected/views/layouts/main.php'
		$this->render('index');
	}


Correct. Well actually ANY call to render() in ANY action, in ANY controller. :)

When you call render(), Yii calls the primary layout (ie, column1), which in-turn calls 'layouts/main.php' the is referenced in the ->beginContent() line at the beginning of the columnX layout. If you look in the 'main.php', you will see
<?php echo $content; ?>
this is where the html from the columX layout is inserted. If you look at the columnX file there is also a
<?php echo $content; ?>
, this is where the actual page content is inserted.

So when you call render('index'), Yii renders the index page and places it in the $content variable. Then it looks at $this->layout, replaces $content with the layout file (placing index $content in in the rendering), then takes that information and surrounds it with the mIn layout, then sends it all back to the browser.
Do, or do not. There is no 'try.' Jedi Master Yoda
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