Zend_Navigation带隐藏页面 [英] Zend_Navigation with hidden pages

查看:101
本文介绍了Zend_Navigation带隐藏页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从PHP数组中加载了Zend_Navigation(但这是不相关的...),并且我正在使用导航菜单帮助程序根据加载的导航生成菜单.某些菜单项一定不能出现在输出的菜单中,因此我只需在该页面的数组中设置'visible'=> false"就可以了!但是,如果访问隐藏"菜单的URL,则findActive($ container)视图帮助器方法将返回一个空数组,因此不会返回容器中的页面,即使它应该返回(例如该页面不存在) );将浏览器标题留空,等等.

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.

由于菜单导航助手和导航视图助手都使用可见"选项(通过方法accept($ page))来丢弃页面,因此此设置对我而言是无用的.

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?

推荐答案

我实际上刚刚找到了一种更为优雅的解决方案.只需在您的findActive()调用之前添加以下行,它就会返回一个不可见的页面(如果已选中):

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:

$this->navigation()->setRenderInvisible(true);

例如,以下代码:

Zend_Debug::dump($this->navigation()
                      ->findActive($this->navigation()->getContainer()));
$this->navigation()->setRenderInvisible(true);
Zend_Debug::dump($this->navigation()
                      ->findActive($this->navigation()->getContainer()));

产生:

array(0) {
}
array(2) {
  ["page"] => object(Zend_Navigation_Page_Mvc)#33 (24) {
    ... PAGE INFORMATION ...
  }
  ["depth"] => int(0)
}

奇怪的是,它不会影响菜单的呈现-即隐藏的页面仍处于隐藏状态.但这并没有多大意义,因此我建议再次将其设置为false,以确保将来不会引起问题.

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.

这篇关于Zend_Navigation带隐藏页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆