Previous topic

Next topic

Containers

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.

Creating containers

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.

Removing pages

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.

Finding pages

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
$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').

Other operations

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.