1
votes

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?

2

2 Answers

2
votes

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.

0
votes

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.