Here is my code,
can’t highlight menu item as
<?php $this->widget(‘zii.widgets.CMenu’,array(
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Project', 'url'=>array('/project')),
array('label'=>'Issue', 'url'=>array('/issue')),
array('label'=>'User', 'url'=>array('/user')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
),
)); ?>
following code can highlight menu item automatically, after add the "/index"
<?php $this->widget(‘zii.widgets.CMenu’,array(
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Project', 'url'=>array('/project/index')),
array('label'=>'Issue', 'url'=>array('/issue/index')),
array('label'=>'User', 'url'=>array('/user/index')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
),
)); ?>
GSTAR:
Here is an example of one of my CMenu list items:
array('label'=>'News', 'url'=>array('/news/index'), 'active'=>Yii::app()->controller->id=='news'),
So here I have to specify that the menu item has active class if the controller id is news. So this also keeps the menu item active for url /news/view
However I recall in the previous menu implementation in Yii 1.0 (MainMenu widget) it did this automatically, i.e. it determines what the controller is based on the link url/route (so you do not need to specify ‘active’ property). The menu item is active for all of its own actions without having to specify the ‘active’ property.
Any reason why this functionality would have been removed from CMenu widget in Yii 1.1?