在我的布局脚本中,我也需要生成/渲染我的菜单。
如果菜单项有子菜单,我会更改菜单项,以便呈现<li
class =“submenu” >
原因是如果子页面退出,我会在<li>
元素上有一个图像!
<ul>
<li>
<a href="/da/front/news">Nyt</a>
</li>
<li class="submenu">
<a href="/da/front/events">Aktiviteter</a>
<ul">
<li>
<a href="/da/front/document/get/document/barserves-2010-2/doctype/html">Barvagt</a>
</li>
<li>
<a href="/da/front/events/history">Afsluttede aktiviteter</a>
</li>
</ul>
</li>
<ul>
这是我的布局脚本
的一部分<?php
$config = new Zend_Config_Xml ( APPLICATION_PATH . '/configs/navigation/front.xml' );
$container = new Zend_Navigation ( $config );
$this->navigation($container);
echo $this->navigation()->menu()->render();
答案 0 :(得分:4)
找到解决方案
我的布局文件
<?php
global $config;
$menuconfig = new Zend_Config_Xml ( $config->navigation->file );
$container = new Zend_Navigation ( $menuconfig );
$this->navigation($container);
$partial = array('menu.phtml','front');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
?>
我的部分文件
<?php
$html = array ();
$iterator = new RecursiveIteratorIterator ( $this->container, RecursiveIteratorIterator::SELF_FIRST );
$prevDepth = - 1;
foreach ( $iterator as $page ) {
$depth = $iterator->getDepth ();
$isActive = $page->isActive ( true );
if ($depth > $prevDepth) {
$html [] = '<ul>' . "\n";
} else if ($prevDepth > $depth) {
for($i = $prevDepth; $i > $depth; $i --) {
$html [] = '</li>' . "\n";
$html [] = '</ul>' . "\n";
}
$html [] = ' </li>' . "\n";
} else {
$html [] = ' </li>' . "\n";
}
if ($page->haspages ()) {
$liClass = $isActive ? ' class="active submenu"' : ' class="submenu"';
} else {
$liClass = $isActive ? ' class="active"' : '';
}
$html [] = '<li' . $liClass . '>' . "\n";
$html [] = '<a href="' . $page->getHref () . '">' . $page->getLabel () . '</a>' . "\n";
$prevDepth = $depth;
}
echo join ( PHP_EOL, $html );
答案 1 :(得分:2)
您可以向导航项添加css类或ID。看起来你的导航是从xml生成的,所以:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<navigation>
<articles>
<label>Articles</label>
<class>submenu</class>
<controller>articles</controller>
<action>index</action>
<pages>
<example>
<label>example</label>
<id>page1</id>
<controller>articles</controller>
<action>index</action>
</example>
</pages>
</articles>
</navigation>
</config>
如果你没有延长Zend_Navigation
答案 2 :(得分:0)
这是为css吗?为什么不使用名为“navigation”的包装div然后转到:
div#navigation ul li ul