Documentation

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\AbstractContainer can not be instantiated directly. Use Zend\Navigation\Navigation if you
want to instantiate a container.

Zend\Navigation\Navigation can be constructed entirely empty, or take an array or a Zend\Config\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, a
config object or a Zend\Navigation\Page\AbstractPage instance.

/* * Create a container from an array * * Each element in the array will be passed to * Zend\Navigation\Page\AbstractPage::factory() when constructing. */$container=newZend\Navigation\Navigation(array(array('label'=>'Page 1','id'=>'home-link','uri'=>'/',),array('label'=>'Zend','uri'=>'http://www.zend-project.com/','order'=>100,),array('label'=>'Page 2','controller'=>'page2','pages'=>array(array('label'=>'Page 2.1','action'=>'page2_1','controller'=>'page2','class'=>'special-one','title'=>'This element has a special class','active'=>true,),array('label'=>'Page 2.2','action'=>'page2_2','controller'=>'page2','class'=>'special-two','title'=>'This element has a special class too',),),),array('label'=>'Page 2 with params','action'=>'index','controller'=>'page2',// specify a param or two,'params'=>array('format'=>'json','foo'=>'bar',)),array('label'=>'Page 2 with params and a route','action'=>'index','controller'=>'page2',// specify a route name and a param for the route'route'=>'nav-route-example','params'=>array('format'=>'json',),),array('label'=>'Page 3','action'=>'index','controller'=>'index','module'=>'mymodule','reset_params'=>false,),array('label'=>'Page 4','uri'=>'#','pages'=>array(array('label'=>'Page 4.1','uri'=>'/page4','title'=>'Page 4 using uri','pages'=>array(array('label'=>'Page 4.1.1','title'=>'Page 4 using mvc params','action'=>'index','controller'=>'page4',// let's say this page is active'active'=>'1',)),),),),array('label'=>'Page 0?','uri'=>'/setting/the/order/option',// setting order to -1 should make it appear first'order'=>-1,),array('label'=>'Page 5','uri'=>'/',// this page should not be visible'visible'=>false,'pages'=>array(array('label'=>'Page 5.1','uri'=>'#','pages'=>array(array('label'=>'Page 5.1.1','uri'=>'#','pages'=>array(array('label'=>'Page 5.1.2','uri'=>'#',// let's say this page is active'active'=>true,),),),),),),),array('label'=>'ACL page 1 (guest)','uri'=>'#acl-guest','resource'=>'nav-guest','pages'=>array(array('label'=>'ACL page 1.1 (foo)','uri'=>'#acl-foo','resource'=>'nav-foo',),array('label'=>'ACL page 1.2 (bar)','uri'=>'#acl-bar','resource'=>'nav-bar',),array('label'=>'ACL page 1.3 (baz)','uri'=>'#acl-baz','resource'=>'nav-baz',),array('label'=>'ACL page 1.4 (bat)','uri'=>'#acl-bat','resource'=>'nav-bat',),),),array('label'=>'ACL page 2 (member)','uri'=>'#acl-member','resource'=>'nav-member',),array('label'=>'ACL page 3 (admin','uri'=>'#acl-admin','resource'=>'nav-admin','pages'=>array(array('label'=>'ACL page 3.1 (nothing)','uri'=>'#acl-nada',),),),array('label'=>'Zend Framework','route'=>'zf-route',),));

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.

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(...), findOneByTitle(...), findAllByController(...), etc. Finder methods
also work on custom properties, such as findByFoo('bar').

The method hasPage(Zend\Navigation\Page\AbstractPage$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)>0.

The toArray() method converts the container and the pages in it to an array. This can be useful for serializing
and debugging.