I know it's already been answered, but I found different solution, because one posted by Marshall didn't work for me. I guess it's because I am not using action/controller in my menu, but routes instead.
My menu entry looks like this:
array(
'label' => 'cms-nav_users',
'access_module' => 'user',
'resource' => 'user_admin',
'route' => 'admin_user',
'pages' => array(
array(
'label' => 'cms-nav_companies',
'access_module' => 'user',
'route' => 'company_admin',
'resource' => 'company_admin',
),
array(
'label' => 'cms-nav_users-list',
'access_module' => 'company',
'route' => 'admin_user',
'resource' => 'user_admin',
),
),
),
I came up with a solution based on my own menu template (partial). Basically there is a foreach loop which checks if any of subpages is active and if there is one - marks parent as active, it looks like this:
$active = false;
if (!empty($page->pages))
{
foreach ($page->pages as $subpage)
{
if ($subpage->isActive()) $active = true;
}
}
$html[] = ($active) ? 'class="active"' : '';
Hope it helps someone :)
UPDATE
Actually I found out that you can use Zend Framework's own isActive() with true
parameter, as seen in source code:
Zend_Navigation_Page_Mvc::isActive($recursive = false)
Both ways will work, but this one seams more proper.