سؤال

In Zend Framework 2 I use ZendNavigation for the main navigation and the breadcrumb-navigation. I want the Breadcrumb-Navigation to show on every page, but I do not want every page to appear in the main navigation.

So in other words I want some pages to show ONLY in breadcrumb navigation.

Is there any way to achieve this? Maybe an option that can be set in the navigation-array? Or do I need to create two different navigations and use one as main navigation and the other as breadcrumb?

هل كانت مفيدة؟

المحلول

Edit

It doesn't really make sense to duplicate the 'pages' configuration as you can instruct the view helper to render what you need. So you can use the same navigation container to render different menus (e.g. breadcrumb vs main navigation).

You can do this by either using the provided breadcrumb methods such as setMaxDepth() or setMinDepth(). Alternatively, for more flexibility, use a view partial as I explained bellow.

In each case you are simply filtering down the complete container into the seletion you want to render.


You can use a view partial to render the breadcrumbs.

This method will find the deepest active page and pass an array of pages that leads to the active page to the partial view script.

The example in the attached link uses array_map to render the contents of $this->pages, however you can achieve the same result with a loop.

foreach($this->pages as $page) {
  printf('<a href="%s">%s</a>', $page->getHref(), $page->getLabel());
}

Keep in mind however you will now need to check the accessibility of the page manually for the current user if you are using the ACL - This can be done using the methods available for MVC or URL pages

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top