我使用Zend_Navigation制作菜单。 问题是我检测到几次“活动菜单”,即当前页面的“li”。
这是我的navigation.xml
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<home>
<label>Accueil</label>
<controller>index</controller>
</home>
<search>
<label>Riads</label>
<controller>search</controller>
<action>index</action>
<params>
<q>allriads</q>
</params>
</search>
<last>
<label>Dernières Minutes</label>
<uri>#</uri>
</last>
<promotion>
<label>Promotions</label>
<uri>#</uri>
</promotion>
<groupes>
<label>Groupes</label>
<uri>#</uri>
</groupes>
<contact>
<label>Contact</label>
<controller>apropros</controller>
<action>contact</action>
</contact>
</nav>
这是我的bootstrap中的代码
/**
* @return Zend_Navigation
*/
protected function _initNavigation()
{
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$this->_view->navigation(new Zend_Navigation($config));
$activeNav = $this->_view->navigation()->findByController('index');
$activeNav->active = true;
$activeNav->setClass("active");
}
这是HTML生成的
<ul class="navigation">
<li class="active">
<a class="active" href="/v2/">Accueil</a>
</li>
<li class="active">
<a href="/v2/search/index/q/allriads">Riads</a>
</li>
<li>
<a href="#">Dernières Minutes</a>
</li>
<li>
<a href="#">Promotions</a>
</li>
<li>
<a href="#">Groupes</a>
</li>
<li>
<a href="/v2/apropros/contact">Contact</a>
</li>
</ul>
好的代码必须是:
<ul class="navigation">
<li>
<a href="/v2/">Accueil</a>
</li>
<li>
<a href="/v2/search/index/q/allriads">Riads</a>
</li>
[...]
解决方案是什么?
此致
答案 0 :(得分:1)
我的解决方案
更改你的Bootrasp.php:
public function _initNavigation()
{
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
Zend_Registry::set('Zend_Navigation', $navigation);
}
在你的layout.phtml中
<?=$this->navigation()->menu()->renderPartial(null, 'shared/menu.phtml')?>
部分文件中的: /application/views/shared/menu.phtmt 写下这个:
<ul class="navigation">
<?
foreach ($this->container as $page) :
/** @var $page Zend_Navigation_Page_Mvc */
?>
<li class="<?=$page->isActive(true) ? 'active' : ''?>">
<a href="<?=$page->getHref()?>"><b><?=$page->label?></b></a>
</li>
<? endforeach; ?>
</ul>
通过执行此操作,它会禁止Zend_Navigator生成的html,但您决定生成html! 我希望看看有帮助!