Menu Highlight

Hi All,

How do I keep a single menu item highlighted when using 2 different Controller? I have made new links in the standard Yii generated code, but now the menu item is not highlighted when clicking on them.

This is what I got:




$this->menu=array(

	array('label'=>'Manage Categories', 'url'=>array('/productCategory/admin'), 'active'=>true),

	array('label'=>'Create Category', 'url'=>array('/productCategory/create')),

	array('label'=>'Manage Products', 'url'=>array('/product/admin')),

	array('label'=>'Create Product', 'url'=>array('/product/create')),

);



When any of the /product/admin is clicked the menu is Highlighted, but none of the other highlight the menu. How can I specify in the URL’s above to highlight the specific menu item?

Thanks

You have forced set ‘active’=>true for the first menu item - so it will always display that line item as active, unless you regenerate the menu again for each call.

If menu is not getting auto-activated based on your detected url … you may pass the active states yourself for each controller action. Something like this.




$this->menu=[

    ['label'=>'Manage Categories', 'url'=>['/productCategory/admin'], 'active'=>$active1],

    ['label'=>'Create Category', 'url'=>['/productCategory/create'], 'active'=>$active2],

    ['label'=>'Manage Products', 'url'=>['/product/admin'], 'active'=>$active3],

    ['label'=>'Create Product', 'url'=>['/product/create'], 'active'=>$active4],

];



You can pass the variables $active1 to $active4 to your view from the controller action when it calls the render view method.