I’m using Yii’s CMenu to generate menu in the following way:
$this->widget('zii.widgets.CMenu', array(
'items'=>$this->mainMenu,
'lastItemCssClass'=>'mitem-last',
'activeCssClass'=>'mitem-active',
'activateParents'=>true
));
I am displaying this menu on page index.php?r=site/home and was expecting the following menu item to have mitem-active class:
[2] => Array
(
[label] => test
[url] => /index.php?r=site/home
)
However the item is rendered as
<li><a href="/index.php?r=site/home">test</a></li>
If I’m not mistaken index.php?r=site/home has route site/home (which is also the output of $this->route), and as a matter of fact the link was created using
$link['url']=$this->createUrl(current($mitem['url']),$params);
where current($mitem['url']) outputs site/home and $params is just array().
Am I missing something?
EDIT: $this->mainMenu is an array made up off multiple $links built in a loop (from xml).
$this->mainMenu = array();
foreach($xml->mitem as $mitem){
$link=array();
... compute some values like $link['label'], $params etc ...
$link['url']=$this->createUrl(current($mitem['url']),$params);
$this->mainMenu[]=$link;
}
For CMenu, “items” array format is:
not
If your item looks like this:
It does not work.
Your item must be like this: