我在xml中有一个简单的导航设置,如下所示:
<nav>
<page1>
<controller>foo</controller>
<route>default</route>
<pages>
<p1sub1>
<controller>foo</controller>
<action>bar</action>
<route>foobar</route>
<params>
<bar>specialId</bar>
</params>
</p1sub1>
<p1sub2>
<controller>foo</controller>
<action>bum</action>
</p1sub2>
</pages>
</page1>
<page2>
<controller>fee</controller>
<route>default</route>
<pages>
<p2sub1>
<controller>fee</controller>
<action>zip</action>
</p2sub1>
<p2sub2>
<controller>fee</controller>
<action>zap</action>
</p2sub2>
</pages>
</page2>
</nav>
加上一个如下所示的路线定义:
routes.foobar.route = "foo/:specialId/bar"
routes.foobar.defaults.controller = foo
routes.foobar.defaults.action = bar
routes.foobar.defaults.specialId = 999
在我的引导程序中,我将此导航配置分配给视图:
$config = new Zend_Config_Xml('path/to/nav.xml', 'nav');
$navigation = new Zend_Navigation($config);
$this->getResource('layoutview')->navigation($navigation);
然后,在我的布局中,我这样做是为了渲染顶级:
<?= $this->navigation()->menu()->setMaxDepth(0) ?>
需要在视图脚本中为调用的控制器操作呈现下一级菜单,因此:
<?= $this->navigation()->menu()->setOnlyActiveBranch(true)->setRenderParents(false) ?>
如果我访问/ foo / bum,/ fee / zip或/ fee / zap,它们都按预期工作。我得到两个正确渲染的菜单,突出显示相应的菜单项。奇妙。但是......当我访问/ foo / 123 / bar时,我根本没有菜单。我现在花了很多时间看着这个,调试/单步执行继承噩梦,即Zend导航及其相关的菜单渲染,但我根本无法理解它为什么这样做。我再也看不到树木了。任何指针都将非常感激。
答案 0 :(得分:0)
典型。在发布的几分钟内,我自己解决了。我只是从导航的XML定义中删除了 params 节点。而不是
<controller>foo</controller>
<action>bar</action>
<route>foobar</route>
<params>
<bar>specialId</bar>
</params>
我使用了这个
<controller>foo</controller>
<action>bar</action>
<route>foobar</route>
Simples。