Not wanting to add any confusion here but…
@zaccaria I understand that this is typically how we use the layouts but the class reference here
Suggest that there might be a bit more to it than that. Usually we use column1 or column2 layout. But I think with only column1 and column2 this feature is under utilized.
$this->beginContent('path/to/view');
// ... content to be decorated
$this->endContent();
If you take a basic install
in the controller specify some custom layout.
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->layout = 'columnxx';
$this->render('index');
}
create a new layout file (columnxx)
<?php $this->beginContent('//layouts/main'); ?>
<div class="container">
<div class="span-19">
<div id="content">
<?php echo $content; ?>
</div><!-- content -->
</div>
<div class="span-5 last">
<div id="sidebar">
<?php
$this->beginWidget('zii.widgets.CPortlet', array(
'title'=>'Operations',
));
$this->widget('zii.widgets.CMenu', array(
'items'=>$this->menu,
'htmlOptions'=>array('class'=>'operations'),
));
$this->endWidget();
?>
</div><!-- sidebar -->
</div>
<div class="span-24"><?php echo Yii::app()->name ?></div>
</div>
<?php $this->endContent(); ?>
We can access Yii::app()->name
The reason we use the variable $content is because of the render method.
This is in CController a class that all of our controllers inherit (typically)
public function render($view,$data=null,$return=false)
{
$output=$this->renderPartial($view,$data,true);
if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
// this line is setting the value of $content
$output=$this->renderFile($layoutFile,array('content'=>$output),true);
//
$output=$this->processOutput($output);
if($return)
return $output;
else
echo $output;
}
I’m pretty sure if we create our own ‘render’ method in a controller or in the controller component we will be able to process more than one variable once we are in the layout.
One day when I have time
I will look into this!
doodle