Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at:
https://docs.zendframework.com/
Containers - Zend_Navigation
Containers have methods for adding, retrieving, deleting and iterating pages. Containers implement the » SPL interfaces RecursiveIterator and Countable, meaning that a container can be iterated using the SPL RecursiveIteratorIterator class.
Zend_Navigation_Container is abstract, and can not be instantiated directly. Use Zend_Navigation if you want to instantiate a container.
Zend_Navigation can be constructed entirely empty, or take an array or a Zend_Config object with pages to put in the container. Each page in the given array/config will eventually be passed to the addPage() method of the container class, which means that each element in the array/config can be an array or a config object, or a Zend_Navigation_Page instance.
Example #1 Creating a container using an array
Example #2 Creating a container using a config object
Example for INI:
Example for JSON:
Example for XML:
Example for YAML:
Adding pages to a container can be done with the methods addPage(), addPages(), or setPages(). See examples below for explanation.
Example #3 Adding pages to a container
Removing pages can be done with removePage() or removePages(). The first method accepts a an instance of a page, or an integer. The integer corresponds to the order a page has. The latter method will remove all pages in the container.
Example #4 Removing pages from a container
Containers have finder methods for retrieving pages. They are findOneBy($property, $value, $useRegex = false), findAllBy($property, $value, $useRegex = false), and findBy($property, $value, $all = false, $useRegex = false). Those methods will recursively search the container for pages matching the given $page->$property == $value or when regular expressions are used: preg_match($value, $page->$property). The first method, findOneBy(), will return a single page matching the property with the given value, or NULL if it cannot be found. The second method will return all pages with a property matching the given value. The third method will call one of the two former methods depending on the $all flag.
The finder methods can also be used magically by appending the property name to findBy, findOneBy, or findAllBy, e.g. findOneByLabel('Home') to return the first matching page with label 'Home'. Other combinations are findByLabel(...), findOnyByTitle(...), findAllByController(...), etc. Finder methods also work on custom properties, such as findByFoo('bar').
Example #5 Finding pages in a container
Use regular expressions to find pages:
Zend_Navigation_Container implements RecursiveIteratorIterator, and can be iterated using any Iterator class. To iterate a container recursively, use the RecursiveIteratorIterator class.
Example #6 Iterating a container
The method hasPage(Zend_Navigation_Page $page) checks if the container has the given page. The method hasPages() checks if there are any pages in the container, and is equivalent to count($container) > 1.
The toArray() method converts the container and the pages in it to an array. This can be useful for serializing and debugging.
Example #7 Converting a container to an array
© 2006-2021 by Zend by Perforce. Made with by awesome contributors.
This website is built using zend-expressive and it runs on PHP 7.