| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect2 id="zend.navigation.pages.custom">
- <title>Creating custom page types</title>
- <para>
- When extending <classname>Zend_Navigation_Page</classname>, there is
- usually no need to override the constructor or the methods
- <methodname>setOptions()</methodname> or <methodname>setConfig()</methodname>. The page
- constructor takes a single parameter, an <type>Array</type> or a
- <classname>Zend_Config</classname> object, which is passed to
- <methodname>setOptions()</methodname> or <methodname>setConfig()</methodname> respectively.
- Those methods will in turn call <methodname>set()</methodname> method, which
- will map options to native or custom properties. If the option
- <property>internal_id</property> is given, the method will first look for a
- method named <methodname>setInternalId()</methodname>, 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
- <command>$internalId = $page->internal_id;</command> or
- <command>$internalId = $page->get('internal_id');</command>.
- </para>
- <example id="zend.navigation.custom.example.simple">
- <title>The most simple custom page</title>
- <para>
- The only thing a custom page class needs to implement is the
- <methodname>getHref()</methodname> method.
- </para>
- <programlisting language="php"><![CDATA[
- class My_Simple_Page extends Zend_Navigation_Page
- {
- public function getHref()
- {
- return 'something-completely-different';
- }
- }
- ]]></programlisting>
- </example>
- <example id="zend.navigation.custom.example.properties">
- <title>A custom page with properties</title>
- <para>
- When adding properties to an extended page, there is no need
- to override/modify <methodname>setOptions()</methodname> or
- <methodname>setConfig()</methodname>.
- </para>
- <programlisting language="php"><![CDATA[
- class My_Navigation_Page extends Zend_Navigation_Page
- {
- private $_foo;
- private $_fooBar;
- public function setFoo($foo)
- {
- $this->_foo = $foo;
- }
- public function getFoo()
- {
- return $this->_foo;
- }
- public function setFooBar($fooBar)
- {
- $this->_fooBar = $fooBar;
- }
- public function getFooBar()
- {
- return $this->_fooBar;
- }
- public function getHref()
- {
- return $this->foo . '/' . $this->fooBar;
- }
- }
- // can now construct using
- $page = new My_Navigation_Page(array(
- 'label' => 'Property names are mapped to setters',
- 'foo' => 'bar',
- 'foo_bar' => 'baz'
- ));
- // ...or
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'My_Navigation_Page',
- 'label' => 'Property names are mapped to setters',
- 'foo' => 'bar',
- 'foo_bar' => 'baz'
- ));
- ]]></programlisting>
- </example>
- </sect2>
|