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
Pages - Zend_Navigation
Zend_Navigation ships with two page types:
MVC pages – using the class Zend_Navigation_Page_Mvc
URI pages – using the class Zend_Navigation_Page_Uri
params). URI pages are defined by a single property
uri, which give you the full flexibility to link off-site pages or do other things with the generated links (e.g. an URI that turns into
All page classes must extend Zend_Navigation_Page, and will thus share a common set of features and properties. Most notably they share the options in the table below and the same initialization process.
Option keys are mapped to
set methods. This means that
order maps to the method setOrder(),
reset_params maps to the method
setResetParams(). If there is no setter method for
the option, it will be set as a custom property of the page.
Read more on extending Zend_Navigation_Page in Creating custom page types.
||String||NULL||A page label, such as 'Home' or 'Blog'.|
|| String |
||NULL||An id tag/attribute that may be used when rendering the page, typically in an anchor element.|
||String||NULL||A CSS class that may be used when rendering the page, typically in an anchor element.|
A short page description, typically for using
||String||NULL||Specifies a target that may be used for the page, typically in an anchor element.|
This attribute assigns an access key to an
||String||NULL||The fragment identifier (anchor identifier) pointing to an anchor within a resource that is subordinate to another, primary resource. The fragment identifier introduced by a hash mark '#'. Example: http://www.example.org/foo.html#bar ('bar' is the fragment identifier)|
Specifies forward relations for the page.
Each element in the array is a key-value pair, where the
key designates the relation/link type, and the value is
a pointer to the linked page. An example of a key-value
Specifies reverse relations for the page. Works exactly
Works like order for elements in
Zend_Form. If specified,
the page will be iterated in a specific order, meaning
you can force a page to be iterated before others by
||String | Zend_Acl_Resource_Interface | NULL||NULL||ACL resource to associate with the page. Read more in the section on ACL integration in view helpers..|
||String | NULL||NULL||ACL privilege to associate with the page. Read more in the section on ACL integration in view helpers..|
Whether the page should be considered active for the
current request. If active is FALSE or not
given, MVC pages will check its properties against the
request object upon calling
||TRUE||Whether page should be visible for the user, or just be a part of the structure. Invisible pages are skipped by view helpers.|
||Array | Zend_Config | NULL||NULL||Child pages of the page. This could be an Array or Zend_Config object containing either page options that can be passed to the factory() method, or actual Zend_Navigation_Page instances, or a mixture of both.|
Note: Custom properties
All pages support setting and getting of custom properties by use of the magic methods __set($name, $value), __get($name), __isset($name) and __unset($name). Custom properties may have any value, and will be included in the array that is returned from
$page->toArray(), which means that pages can be serialized/deserialized successfully even if the pages contains properties that are not native in the page class.
Both native and custom properties can be set using
$page->set($name, $value)and retrieved using
$page->get($name), or by using magic methods.
Example #1 Custom page properties
This example shows how custom properties can be used.
MVC pages are defined using MVC parameters known from the Zend_Controller component. An MVC page will use Zend_Controller_Action_Helper_Url internally in the getHref() method to generate hrefs, and the isActive() method will intersect the Zend_Controller_Request_Abstract params with the page's params to determine if the page is active.
||String||NULL||Action name to use when generating href to the page.|
||String||NULL||Controller name to use when generating href to the page.|
||String||NULL||Module name to use when generating href to the page.|
||Array||array()||User params to use when generating href to the page.|
||String||NULL||Route name to use when generating href to the page.|
||TRUE||Whether user params should be reset when generating href to the page.|
||TRUE||Whether href should be encoded when assembling URL.|
Note: The three examples below assume a default MVC setup with the
defaultroute in place.
The URI returned is relative to the
baseUrlin Zend_Controller_Front. In the examples, the baseUrl is '/' for simplicity.
Example #2 getHref() generates the page URI
This example shows that MVC pages use
to generate URIs when calling
Example #3 isActive() determines if page is active
This example shows that MVC pages determine whether they are active by using the params found in the request object.
Example #4 Using routes
Routes can be used with MVC pages. If a page has a route, this route will be used in getHref() to generate the URL for the page.
Note: Note that when using the
routeproperty in a page, you should also specify the default params that the route defines (module, controller, action, etc.), otherwise the isActive() method will not be able to determine if the page is active. The reason for this is that there is currently no way to get the default params from a Zend_Controller_Router_Route_Interface object, nor to retrieve the current route from a Zend_Controller_Router_Interface object.
Example #5 Set parameters to use when assembling URL
Pages of type Zend_Navigation_Page_Uri can be
used to link to pages on other domains or sites, or to implement
custom logic for the page. URI pages are simple; in addition
to the common page options, a URI page takes only one option —
uri will be returned when
$page->getHref(), and may be a
String or NULL.
Note: Zend_Navigation_Page_Uri will not try to determine whether it should be active when calling
$page->isActive(). It merely returns what currently is set, so to make a URI page active you have to manually call
activeas a page option when constructing.
||String||NULL||URI to page. This can be any string or NULL.|
When extending Zend_Navigation_Page, there is usually no need to override the constructor or the methods setOptions() or setConfig(). The page constructor takes a single parameter, an Array or a Zend_Config object, which is passed to setOptions() or setConfig() respectively. Those methods will in turn call set() method, which will map options to native or custom properties. If the option internal_id is given, the method will first look for a method named setInternalId(), and pass the option to this method if it exists. If the method does not exist, the option will be set as a custom property of the page, and be accessible via $internalId = $page->internal_id; or $internalId = $page->get('internal_id');.
Example #6 The most simple custom page
The only thing a custom page class needs to implement is the getHref() method.
Example #7 A custom page with properties
When adding properties to an extended page, there is no need to override/modify setOptions() or setConfig().
All pages (also custom classes), can be created using the page
factory, Zend_Navigation_Page::factory(). The factory
can take an array with options, or a
Zend_Config object. Each key in the
array/config corresponds to a page option, as seen in the
section on Pages.
If the option
uri is given and no MVC options are
action, controller, module, route), an URI
page will be created. If any of the MVC options are given, an
MVC page will be created.
type is given, the factory will assume the value to
be the name of the class that should be created. If the value is
uri and MVC/URI page will be created.
Example #8 Creating an MVC page using the page factory
Example #9 Creating a URI page using the page factory
Example #10 Creating a custom page type using the page factory
To create a custom page type using the factory, use the option
type to specify a class name to instantiate.