Zend_Navigation 带有隐藏页面

发布于 2024-09-07 13:11:06 字数 329 浏览 7 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱娆 2024-09-14 13:11:06

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

$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()));

Produces:

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

奇怪的部分是它不会影响菜单的呈现 - 即隐藏页面仍然隐藏。但这没有多大意义,所以我建议再次将其设置为 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:

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

For example, the following code:

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

Produces:

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

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.

绻影浮沉 2024-09-14 13:11:06

好吧,经过一番修改,我最终选择了这个选项:

  1. 我不想在菜单中显示的页面有一个额外的选项:“menuItem”。 (此选项不是强制性的,可能为空/未设置)
  2. 在我的布局脚本中,我递归地遍历所有页面并在 的所有页面上设置 $page->visible = false; false === $page->menuItem 为 true
  3. 我调用菜单导航助手,

因为只有在调用视图脚本(设置了 headTitle)后才调用菜单导航助手,并且检查是在我的布局,然后我可以安全地将任何页面的可见属性设置为 false,而不会产生负面缺点。

well, after some tinkering, I finally chose this option:

  1. I have an extra option for the page that I don't want to show in my menu: "menuItem". (this option is not mandatory and may be null/unset)
  2. in my layout's script, I iterate recursively through all the pages and set $page->visible = false; on all pages that false === $page->menuItem is true
  3. I call the menu navigation helper

Since 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文