'items'=>array(
array(
'label'=>'About',
'url'=>array('about/index')
),
about/index
- we get the class on the menu - active.
about/graphic
- we don't get the class on the menu active.
about/print
- we don't get the class on the menu active.
Please note that the menu has NO subitems. Only About.
No mater if the user is on graphic, print or whatever, we wish to have the About highlighted.
How can we accomplish this ?
I've tried to edit that 'url' param a lot. No luck.
Added the
active
param. This worked.I've set that property. Otherwise it wouldn't work.
However, as you can see on the bold line, they say this should be automatically triggered. It wasn't on this case.
I suppose this was the case due to the fact that Yii is expecting a child element of About in order to apply that class, since there's any, we have to force it, to get the parent instead.
Not sure however.
CMenu is comparing item's route to current route, so by default it will work only for
about/index
.I see two ways of forcing it - first is just set
'active' => true
in items list:Or you can subclass CMenu class and overwrite
CMenu::isItemActive($item,$route)
methodsimple but effective:
also... to activate a menu, regardless of the action, just for a controller:
Notes:
add the $controller or $action variables, you can use them for more menu items. Your code will be cleaner.
you'll be 100% sure, the menu items will 'stick' active