| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect2 id="zend.navigation.pages.factory">
- <title>Creating pages using the page factory</title>
- <para>
- All pages (also custom classes), can be created using the page
- factory, <methodname>Zend_Navigation_Page::factory()</methodname>. The factory
- can take an array with options, or a
- <classname>Zend_Config</classname> object. Each key in the
- array/config corresponds to a page option, as seen in the
- section on <link linkend="zend.navigation.pages">Pages</link>.
- If the option <code>uri</code> is given and no <acronym>MVC</acronym> options are
- given (<code>action, controller, module, route</code>), an <acronym>URI</acronym>
- page will be created. If any of the <acronym>MVC</acronym> options are given, an
- <acronym>MVC</acronym> page will be created.
- </para>
- <para>
- If <code>type</code> is given, the factory will assume the value to
- be the name of the class that should be created. If the value is
- <code>mvc</code> or <code>uri</code> and <acronym>MVC</acronym>/URI page will be created.
- </para>
- <example id="zend.navigation.pages.factory.example.mvc">
- <title>Creating an MVC page using the page factory</title>
- <programlisting language="php"><![CDATA[
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'My MVC page',
- 'action' => 'index'
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'Search blog',
- 'action' => 'index',
- 'controller' => 'search',
- 'module' => 'blog'
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'Home',
- 'action' => 'index',
- 'controller' => 'index',
- 'module' => 'index',
- 'route' => 'home'
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'mvc',
- 'label' => 'My MVC page'
- ));
- ]]></programlisting>
- </example>
- <example id="zend.navigation.pages.factory.example.uri">
- <title>Creating a URI page using the page factory</title>
- <programlisting language="php"><![CDATA[
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'My URI page',
- 'uri' => 'http://www.example.com/'
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'Search',
- 'uri' => 'http://www.example.com/search',
- 'active' => true
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'label' => 'My URI page',
- 'uri' => '#'
- ));
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'uri',
- 'label' => 'My URI page'
- ));
- ]]></programlisting>
- </example>
- <example id="zend.navigation.pages.factory.example.custom">
- <title>Creating a custom page type using the page factory</title>
- <para>
- To create a custom page type using the factory, use the option
- <code>type</code> to specify a class name to instantiate.
- </para>
- <programlisting language="php"><![CDATA[
- class My_Navigation_Page extends Zend_Navigation_Page
- {
- protected $_fooBar = 'ok';
- public function setFooBar($fooBar)
- {
- $this->_fooBar = $fooBar;
- }
- }
- $page = Zend_Navigation_Page::factory(array(
- 'type' => 'My_Navigation_Page',
- 'label' => 'My custom page',
- 'foo_bar' => 'foo bar'
- ));
- ]]></programlisting>
- </example>
- </sect2>
|