2
0

Zend_Navigation-Pages-Factory.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.navigation.pages.factory">
  4. <title>Creating pages using the page factory</title>
  5. <para>
  6. All pages (also custom classes), can be created using the page
  7. factory, <methodname>Zend_Navigation_Page::factory()</methodname>. The factory
  8. can take an array with options, or a
  9. <classname>Zend_Config</classname> object. Each key in the
  10. array/config corresponds to a page option, as seen in the
  11. section on <link linkend="zend.navigation.pages">Pages</link>.
  12. If the option <code>uri</code> is given and no <acronym>MVC</acronym> options are
  13. given (<code>action, controller, module, route</code>), an <acronym>URI</acronym>
  14. page will be created. If any of the <acronym>MVC</acronym> options are given, an
  15. <acronym>MVC</acronym> page will be created.
  16. </para>
  17. <para>
  18. If <code>type</code> is given, the factory will assume the value to
  19. be the name of the class that should be created. If the value is
  20. <code>mvc</code> or <code>uri</code> and <acronym>MVC</acronym>/URI page will be created.
  21. </para>
  22. <example id="zend.navigation.pages.factory.example.mvc">
  23. <title>Creating an MVC page using the page factory</title>
  24. <programlisting language="php"><![CDATA[
  25. $page = Zend_Navigation_Page::factory(array(
  26. 'label' => 'My MVC page',
  27. 'action' => 'index'
  28. ));
  29. $page = Zend_Navigation_Page::factory(array(
  30. 'label' => 'Search blog',
  31. 'action' => 'index',
  32. 'controller' => 'search',
  33. 'module' => 'blog'
  34. ));
  35. $page = Zend_Navigation_Page::factory(array(
  36. 'label' => 'Home',
  37. 'action' => 'index',
  38. 'controller' => 'index',
  39. 'module' => 'index',
  40. 'route' => 'home'
  41. ));
  42. $page = Zend_Navigation_Page::factory(array(
  43. 'type' => 'mvc',
  44. 'label' => 'My MVC page'
  45. ));
  46. ]]></programlisting>
  47. </example>
  48. <example id="zend.navigation.pages.factory.example.uri">
  49. <title>Creating a URI page using the page factory</title>
  50. <programlisting language="php"><![CDATA[
  51. $page = Zend_Navigation_Page::factory(array(
  52. 'label' => 'My URI page',
  53. 'uri' => 'http://www.example.com/'
  54. ));
  55. $page = Zend_Navigation_Page::factory(array(
  56. 'label' => 'Search',
  57. 'uri' => 'http://www.example.com/search',
  58. 'active' => true
  59. ));
  60. $page = Zend_Navigation_Page::factory(array(
  61. 'label' => 'My URI page',
  62. 'uri' => '#'
  63. ));
  64. $page = Zend_Navigation_Page::factory(array(
  65. 'type' => 'uri',
  66. 'label' => 'My URI page'
  67. ));
  68. ]]></programlisting>
  69. </example>
  70. <example id="zend.navigation.pages.factory.example.custom">
  71. <title>Creating a custom page type using the page factory</title>
  72. <para>
  73. To create a custom page type using the factory, use the option
  74. <code>type</code> to specify a class name to instantiate.
  75. </para>
  76. <programlisting language="php"><![CDATA[
  77. class My_Navigation_Page extends Zend_Navigation_Page
  78. {
  79. protected $_fooBar = 'ok';
  80. public function setFooBar($fooBar)
  81. {
  82. $this->_fooBar = $fooBar;
  83. }
  84. }
  85. $page = Zend_Navigation_Page::factory(array(
  86. 'type' => 'My_Navigation_Page',
  87. 'label' => 'My custom page',
  88. 'foo_bar' => 'foo bar'
  89. ));
  90. ]]></programlisting>
  91. </example>
  92. </sect2>