我正在使用 zend 导航来创建菜单。我想将默认类“活动”更改为“已选择”,并且我还想将该类添加到活动链接的锚标记。这是我在引导程序中放入的示例代码
protected function _initNavigation()
{
$pages = array(
array(
'module' => 'admin',
'label' => 'Services',
'resource' => 'admin',
'controller' => 'services',
'pages' => array(
array(
'module' => 'admin',
'label' => 'Add Services',
'controller' => 'services',
'action' => 'manage',
'route' => 'default',
),
array(
'module' => 'admin',
'label' => 'View Services',
'controller' => 'services',
'action' => 'view',
'route' => 'default',
),
),
)
);
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config($pages);
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}
在我的布局视图脚本中,我把它放在下面的代码中
echo $this->navigation()->menu()
->setUlId('menu');
电流输出
<ul class="navigation" id="menu">
<li class="active">
<a href="/test/public/admin/services">Services</a>
<ul>
<li>
<a href="/test/public/admin/services/manage">Add Services</a>
</li>
<li class="active">
<a href="/test/public/admin/services/view">View Services</a>
</li>
</ul>
</li>
预期产出
<ul class="navigation" id="menu">
<li>
<a href="/test/public/admin/services">Services</a>
<ul style='display:block;'>
<li>
<a href="/test/public/admin/services/manage">Add Services</a>
</li>
<li>
<a class='selected' href="/test/public/admin/services/view">View Services</a>
</li>
</ul>
</li>