The navigation helpers are used for rendering navigational elements from Zend\Navigation\Navigation instances.
There are 5 built-in helpers:
All built-in helpers extend Zend\View\Helper\Navigation\AbstractHelper, which adds integration with ACL and translation. The abstract class implements the interface Zend\View\Helper\Navigation\HelperInterface, which defines the following methods:
In addition to the method stubs from the interface, the abstract class also implements the following methods:
If a container is not explicitly set, the helper will create an empty Zend\Navigation\Navigation container when calling $helper->getContainer().
Navigation view helpers use the magic method __call() to proxy method calls to the navigation container that is registered in the view helper.
1 2 3 | $this->navigation()->addPage(array(
'type' => 'uri',
'label' => 'New page'));
|
The call above will add a page to the container in the Navigation helper.
The navigation helpers support translation of page labels and titles. You can set a translator of type Zend\I18n\Translator in the helper using $helper->setTranslator($translator).
If you want to disable translation, use $helper->setUseTranslator(false).
The proxy helper will inject its own translator to the helper it proxies to if the proxied helper doesn’t already have a translator.
Note
There is no translation in the sitemap helper, since there are no page labels or titles involved in an XML sitemap.
All navigational view helpers support ACL inherently from the class Zend\View\Helper\Navigation\AbstractHelper. An object implementing Zend\Permissions\Acl\AclInterface can be assigned to a helper instance with $helper->setAcl($acl), and role with $helper->setRole(‘member’) or $helper->setRole(new Zend\Permissions\Acl\Role\GenericRole(‘member’)). If ACL is used in the helper, the role in the helper must be allowed by the ACL to access a page’s resource and/or have the page’s privilege for the page to be included when rendering.
If a page is not accepted by ACL, any descendant page will also be excluded from rendering.
The proxy helper will inject its own ACL and role to the helper it proxies to if the proxied helper doesn’t already have any.
The examples below all show how ACL affects rendering.
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.