Zend Framework双类别菜单处于活动状态 [英] Zend Framework double class menu active
问题描述
我用Zend_Navigation做一个菜单. 问题是我检测到几次活动菜单",即当前页面的"li".
I make a menu with Zend_Navigation. The trouble is that I detect a few times "active menu" that is, the "li" of the current page.
这是我的navigation.xml
Here is my 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>
这是我的引导程序中的代码
Here is the code in my 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>
[...]
解决方案是什么?
此致
推荐答案
我的解决方案
更改您的Bootrasp.php:
change your 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
In your layout.phtml
<?=$this->navigation()->menu()->renderPartial(null, 'shared/menu.phtml')?>
在部分文件中:/application/views/shared/menu.phtmt 编写为:
in the partial file: /application/views/shared/menu.phtmt write this:
<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! 我希望能对您有所帮助!
By doing this, it inhibits the html generated by Zend_Navigator, but you decide to generate the html! I hope to check out was of help!
这篇关于Zend Framework双类别菜单处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!