Zend_Navigation 带有隐藏页面
我从 PHP 数组加载了 Zend_Navigation(但这无关紧要...),并且我正在使用导航菜单助手根据加载的导航生成菜单。某些菜单项不得出现在输出的菜单中,因此我只需在该页面的数组中设置“'visible' => false”即可!但是,如果访问“隐藏”菜单的 URL,则 findActive($container) 视图辅助方法将返回一个空数组,因此不会返回容器中的页面,即使应该返回(就像该页面不存在一样) );将浏览器标题留空等。
由于菜单导航助手和导航视图助手都使用“可见”选项来丢弃页面(通过方法accept($page)),因此此设置在我的情况下毫无用处。
离开这里最好的方法是什么?
I have my Zend_Navigation loaded from a PHP array (but that's irrelevant...) and I'm using the navigation menu helper to generate a menu based on the loaded navigation. Some menu items must not appear in the outputted menu, so I simply set "'visible' => false" in my array for that page and there you go! But if the URL of an 'hidden' menu is accessed, the findActive($container) view helper method returns an empty array, thus the page from the container is not returned, even if it should (like if the page didn't exist); leaving the browser title empty, etc.
Since both the menu navigation helper and the navigation view helper uses the 'visible' option to discard the page (through the method accept($page)), this setting is useless in my case.
What would be the best way to go from here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上我刚刚找到了一个更优雅的解决方案。只需在 findActive() 调用之前添加以下行,如果选择,它将返回一个不可见的页面:
例如,以下代码:
Produces:
奇怪的部分是它不会影响菜单的呈现 - 即隐藏页面仍然隐藏。但这没有多大意义,所以我建议再次将其设置为 false 以确保它不会在将来引起问题。
I actually just found a much more elegant solution. Simply add the following line before your findActive() call, and it will return an invisible page, if selected:
For example, the following code:
Produces:
The curious part is that it doesn't affect the rendering of the menu - i.e. hidden pages are still hidden. That doesn't make much sense though, so I'd recommend setting it to false again to make sure it doesn't cause problems in the future.
好吧,经过一番修改,我最终选择了这个选项:
的所有页面上设置
为 true$page->visible = false;
false === $page->menuItem因为只有在调用视图脚本(设置了 headTitle)后才调用菜单导航助手,并且检查是在我的布局,然后我可以安全地将任何页面的可见属性设置为 false,而不会产生负面缺点。
well, after some tinkering, I finally chose this option:
$page->visible = false;
on all pages thatfalse === $page->menuItem
is trueSince when the menu navigation helper is called only after the view script has been called (headTitle is set), and the check is done in my layout, then I can safely set any page's visible property to false without negative drawbacks.