Hi all!
I’m not sure it this is correct or the best way of doing it, but it works (I think). So I thought it might be useful to someone.
I’ve applied some routes with the urlManager to the menu, instead of urls like “site/services” I made in config
'urlManager' => array(
'showScriptName' => false,
'urlFormat' => 'path',
'rules'=>array(
'services'=>'site/services')
)),
in the main layout with CMenu widget, if you see the items don’t have “controller/action”
$this->widget('application.components.XMenu',array(
'id'=>'mainmenu',
'items'=>array(
array('label'=>'SERVICES ', 'url'=>array('/services')),
),
)); ?>
The CMenu isItemActive() method is not able to match because
!strcasecmp(trim($item['url'][0],'/'),$route)
will never be true because
trim($item['url'][0],'/')= "services"
$route = "site/services"
So I extended the CMenu isItemActive() to
protected function isItemActive($item, $route) {
if (isset($item['url']) && is_array($item['url'])) {
if (Yii::app()->getRequest()->url == $item['url'][0]) {
return true;
} elseif (!strcasecmp(trim($item['url'][0], '/'), $route)) {
return false;
} elseif (count($item['url']) > 1) {
foreach ( array_splice($item['url'], 1) as $name => $value ) {
if (!isset($_GET[$name]) || $_GET[$name] != $value)
return false;
}
return true;
}
return false;
}
}
And like that works.
I’m no expert in Yii or PHP, just a curious, so if anything is wrong please say it.
Thank you all for the help in other issues.
I’m loving it…