Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at 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
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),
findAllBy($property, $value), and
findBy($property, $value, $all = false).
Those methods will recursively search the container for
pages matching the given
$page->$property == $value.
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
The finder methods can also be used magically by appending the
property name to
findAllBy, e.g. findOneByLabel('Home') to
return the first matching page with label
Other combinations are findByLabel(...),
findAllByController(...), etc. Finder
methods also work on custom properties, such as
Example #5 Finding pages in a container
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
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