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