column2.php in my layout folder appears on every page. so all the stuff in column2 appears in the view file on the left. How can I control that ? E.g I don’t need any menus at all in some of my pages.
You can check $this->getUniqueId() for controller id (or module/controller id) with $this->getAction()->getId() for action name - if these two should get the menu items displayed you set true. I.e.:
array(
'label' => '<i class="icon icon-home"></i> Menu item that should be displayed for controller XXX nad action YYY',
'url' => array('/site/index'),
'itemOptions' => array('class'=>''),
'visible' => $this->getUniqueId() == 'XXX' && $this->getAction()->getId() == 'YYY'
),
$this->controller->id and $this->controller->action->id should work as well.
even better push the links into menu array defined on controller like so
// homepage
$this->menu = array(
array('label'=>'About Us', 'url'=>array('/site/index')),
);
// about us page
$this->menu = array(
array('label'=>'Homepage', 'url'=>array('/site/index')),
array('label'=>'Fancy page', 'url'=>array('/site/index')),
);
// some other fancy page
$this->menu = array(
array('label'=>'Homepage', 'url'=>array('/site/index')),
array('label'=>'About Us', 'url'=>array('/site/index')),
);
// to display it just use your code like so
<?php $this->widget('zii.widgets.CMenu', array(
/*'type'=>'list',*/
'encodeLabel'=>false,
'items'=>$this->menu
)); ?>