在我的布局脚本中,我也需要生成/渲染我的菜单。
如果菜单项有一个子菜单,我会更改我的菜单项,以便它会呈现<li
类=“子菜单”>
原因是我会有一张图片<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();
找到了解决方案
我的布局文件
<?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 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)