I have the same problem, my class extends CMenu but doesn’t work the auto “active” on menu items.
I tried these solutions:
[list=1]
[*]SOLUTION 1: override protected function isItemActive($item, $route) but doesn’t work (assign “active” class to items that match partially with current URL)
[*]SOLUTION 2: override protected function isItemActive($item, $route) and call explicitly
$item['active']= ($this->isItemActive($item, $route))?true:false;
but doesn’t works (assign “active” class to items that match partially with current URL)
[*]SOLUTION 3: override public function init() without calling to prent::init()
public function init()
{$this->htmlOptions['id']=$this->getId();}
this bypass the calling to
$this->items=$this->normalizeItems($this->items,$route,$hasActiveChild);
(this function probably cause the bug)
finally apply second solutions and IT WORKS!
[/list]
I report the overriding of isItemActive used in my code:
protected function isItemActive($item, $route) {
if (isset($item['url']) && is_array($item['url'])) {
if(!strcasecmp(Yii::app()->createUrl($item['url'][0], array_slice($item['url'], 1)), $route)){
return true;
}else return false;
}else return false;
}
and this is the function into class tha extends CMenu, it returns the array with menu items:
private function returnMyItems(){
.....
//extract the complete url
$route = Yii::app()->getRequest()->url;
//control if route match the URL create with $item['url']
$item['active']= ($this->isItemActive($item, $route))?true:false;
$items[]= $item;
.....
return $items;
}
This solution is the only one that work for me, note that I used this configuration for main.php
....
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<action:\w+>/*'=>'<controller>/<action>'
),
'showScriptName'=>false,
),
....
this particular configuration uses “/*” into the rule path so all GET parameters pass to createUrl() are attached to the path ( ie $_GET[‘foo’]=1 is attached in this way controller/action/foo/1 )
Sorry for my bad english, I hope that this work may be useful