CMenu in Layout (Column)

I have menus in my layout in the column2.php as below which appear in all the pages , i don’t know how to show specific menu items for specific pages


 <?php $this->widget('zii.widgets.CMenu', array(

			/*'type'=>'list',*/

			'encodeLabel'=>false,

			'items'=>array(

				array('label'=>'<i class="icon icon-home"></i>  Menu item 1<span class="label label-info pull-right">BETA</span>', 'url'=>array('/site/index'),'itemOptions'=>array('class'=>'')),

				array('label'=>'<i class="icon icon-search"></i> Menu item 2 <span class="label label-important pull-right">HOT</span>', 'url'=>'http://www.webapplicationthemes.com/abound-yii-framework-theme/'),

				array('label'=>'<i class="icon icon-envelope"></i> Inbox <span class="badge badge-success pull-right">12</span>', 'url'=>'#'),

				// Include the operations menu

				array('label'=>'OPERATIONS','items'=>$this->menu),

			),

			));?>

		</div>

As you can see above, how can I put an if condition… that if it is page 2 then show menu item 1 and if it is page 3 show menu item 2

There is key ‘visible’, when set to false menu item is not displayed so you can use it to create condition.

Thanks again Bizley I will give it a try

OK so visible is to check if the user is a guest


'visible'=>Yii::app()->user->isGuest

how can i write ‘visible’=>{ when I see this page }

Just to be clear this is a submenu for each page

>>>

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.

MANY THANKS! This is exactly what I wanted!

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

)); ?>