1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.navigation.pages.custom">
4 <title>Creating custom page types</title>
7 When extending <classname>Zend_Navigation_Page</classname>, there is
8 usually no need to override the constructor or the methods
9 <methodname>setOptions()</methodname> or <methodname>setConfig()</methodname>. The page
10 constructor takes a single parameter, an <type>Array</type> or a
11 <classname>Zend_Config</classname> object, which is passed to
12 <methodname>setOptions()</methodname> or <methodname>setConfig()</methodname> respectively.
13 Those methods will in turn call <methodname>set()</methodname> method, which
14 will map options to native or custom properties. If the option
15 <code>internal_id</code> is given, the method will first look for a
16 method named <methodname>setInternalId()</methodname>, and pass the option to this
17 method if it exists. If the method does not exist, the option will be
18 set as a custom property of the page, and be accessible via
19 <code>$internalId = $page->internal_id;</code> or
20 <code>$internalId = $page->get('internal_id');</code>.
23 <example id="zend.navigation.custom.example.simple">
24 <title>The most simple custom page</title>
27 The only thing a custom page class needs to implement is the
28 <methodname>getHref()</methodname> method.
31 <programlisting language="php"><![CDATA[
32 class My_Simple_Page extends Zend_Navigation_Page
34 public function getHref()
36 return 'something-completely-different';
42 <example id="zend.navigation.custom.example.properties">
43 <title>A custom page with properties</title>
46 When adding properties to an extended page, there is no need
47 to override/modify <methodname>setOptions()</methodname> or
48 <methodname>setConfig()</methodname>.
51 <programlisting language="php"><![CDATA[
52 class My_Navigation_Page extends Zend_Navigation_Page
57 public function setFoo($foo)
62 public function getFoo()
67 public function setFooBar($fooBar)
69 $this->_fooBar = $fooBar;
72 public function getFooBar()
74 return $this->_fooBar;
77 public function getHref()
79 return $this->foo . '/' . $this->fooBar;
83 // can now construct using
84 $page = new My_Navigation_Page(array(
85 'label' => 'Property names are mapped to setters',
91 $page = Zend_Navigation_Page::factory(array(
92 'type' => 'My_Navigation_Page',
93 'label' => 'Property names are mapped to setters',