Zend_Layout-Options.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.layout.options">
  4. <title>Zend_Layout Configuration Options</title>
  5. <para>
  6. <classname>Zend_Layout</classname> has a variety of configuration options. These
  7. may be set by calling the appropriate accessors, passing an array or
  8. <classname>Zend_Config</classname> object to the constructor or
  9. <methodname>startMvc()</methodname>, passing an array of options to
  10. <methodname>setOptions()</methodname>, or passing a <classname>Zend_Config</classname>
  11. object to <methodname>setConfig()</methodname>.
  12. </para>
  13. <itemizedlist>
  14. <listitem>
  15. <para>
  16. <emphasis>layout</emphasis>: the layout to use. Uses the
  17. current inflector to resolve the name provided to the
  18. appropriate layout view script. By default, this value is
  19. 'layout' and resolves to 'layout.phtml'. Accessors
  20. are <methodname>setLayout()</methodname> and <methodname>getLayout()</methodname>.
  21. </para>
  22. </listitem>
  23. <listitem>
  24. <para>
  25. <emphasis>layoutPath</emphasis>: the base path to layout view
  26. scripts. Accessors are <methodname>setLayoutPath()</methodname> and
  27. <methodname>getLayoutPath()</methodname>.
  28. </para>
  29. </listitem>
  30. <listitem>
  31. <para>
  32. <emphasis>contentKey</emphasis>: the layout variable used for
  33. default content (when used with the <acronym>MVC</acronym>). Default value is
  34. 'content'. Accessors are <methodname>setContentKey()</methodname> and
  35. <methodname>getContentKey()</methodname>.
  36. </para>
  37. </listitem>
  38. <listitem>
  39. <para>
  40. <emphasis>mvcSuccessfulActionOnly</emphasis>: when using the
  41. <acronym>MVC</acronym>, if an action throws an exception and this flag is
  42. <constant>TRUE</constant>, the layout will not be rendered (this is to prevent
  43. double-rendering of the layout when the <link
  44. linkend="zend.controller.plugins.standard.errorhandler">ErrorHandler
  45. plugin</link> is in use). By default, the flat is <constant>TRUE</constant>.
  46. Accessors are <methodname>setMvcSuccessfulActionOnly()</methodname> and
  47. <methodname>getMvcSuccessfulActionOnly()</methodname>.
  48. </para>
  49. </listitem>
  50. <listitem>
  51. <para>
  52. <emphasis>view</emphasis>: the view object to use when rendering. When used with the
  53. <acronym>MVC</acronym>, <classname>Zend_Layout</classname> will attempt to use the
  54. view object registered with <link
  55. linkend="zend.controller.actionhelpers.viewrenderer">the ViewRenderer</link> if
  56. no view object has been passed to it explicitly. Accessors are
  57. <methodname>setView()</methodname> and <methodname>getView()</methodname>.
  58. </para>
  59. </listitem>
  60. <listitem>
  61. <para>
  62. <emphasis>helperClass</emphasis>: the action helper class to use
  63. when using <classname>Zend_Layout</classname> with the <acronym>MVC</acronym>
  64. components. By default, this is
  65. <classname>Zend_Layout_Controller_Action_Helper_Layout</classname>.
  66. Accessors are <methodname>setHelperClass()</methodname> and
  67. <methodname>getHelperClass()</methodname>.
  68. </para>
  69. </listitem>
  70. <listitem>
  71. <para>
  72. <emphasis>pluginClass</emphasis>: the front controller plugin
  73. class to use when using <classname>Zend_Layout</classname> with the
  74. <acronym>MVC</acronym> components. By default, this is
  75. <classname>Zend_Layout_Controller_Plugin_Layout</classname>. Accessors
  76. are <methodname>setPluginClass()</methodname> and
  77. <methodname>getPluginClass()</methodname>.
  78. </para>
  79. </listitem>
  80. <listitem>
  81. <para>
  82. <emphasis>inflector</emphasis>: the inflector to use when
  83. resolving layout names to layout view script paths; see <link
  84. linkend="zend.layout.advanced.inflector">the
  85. <classname>Zend_Layout</classname> inflector documentation for more
  86. details</link>. Accessors are <methodname>setInflector()</methodname>
  87. and <methodname>getInflector()</methodname>.
  88. </para>
  89. </listitem>
  90. </itemizedlist>
  91. <note>
  92. <title>helperClass and pluginClass must be passed to startMvc()</title>
  93. <para>
  94. In order for the <property>helperClass</property> and
  95. <property>pluginClass</property> settings to have effect, they must be
  96. passed in as options to <methodname>startMvc()</methodname>; if set later, they
  97. have no affect.
  98. </para>
  99. </note>
  100. <sect2 id="zend.layout.options.examples">
  101. <title>Examples</title>
  102. <para>
  103. The following examples assume the following <varname>$options</varname>
  104. array and <varname>$config</varname> object:
  105. </para>
  106. <programlisting language="php"><![CDATA[
  107. $options = array(
  108. 'layout' => 'foo',
  109. 'layoutPath' => '/path/to/layouts',
  110. 'contentKey' => 'CONTENT', // ignored when MVC not used
  111. );
  112. ]]></programlisting>
  113. <programlisting language="php"><![CDATA[
  114. /**
  115. [layout]
  116. layout = "foo"
  117. layoutPath = "/path/to/layouts"
  118. contentKey = "CONTENT"
  119. */
  120. $config = new Zend_Config_Ini('/path/to/layout.ini', 'layout');
  121. ]]></programlisting>
  122. <example id="zend.layout.options.examples.constructor">
  123. <title>Passing options to the constructor or startMvc()</title>
  124. <para>
  125. Both the constructor and the <methodname>startMvc()</methodname> static
  126. method can accept either an array of options or a
  127. <classname>Zend_Config</classname> object with options in order to
  128. configure the <classname>Zend_Layout</classname> instance.
  129. </para>
  130. <para>
  131. First, let's look at passing an array:
  132. </para>
  133. <programlisting language="php"><![CDATA[
  134. // Using constructor:
  135. $layout = new Zend_Layout($options);
  136. // Using startMvc():
  137. $layout = Zend_Layout::startMvc($options);
  138. ]]></programlisting>
  139. <para>
  140. And now using a config object:
  141. </para>
  142. <programlisting language="php"><![CDATA[
  143. $config = new Zend_Config_Ini('/path/to/layout.ini', 'layout');
  144. // Using constructor:
  145. $layout = new Zend_Layout($config);
  146. // Using startMvc():
  147. $layout = Zend_Layout::startMvc($config);
  148. ]]></programlisting>
  149. <para>
  150. Basically, this is the easiest way to customize your
  151. <classname>Zend_Layout</classname> instance.
  152. </para>
  153. </example>
  154. <example id="zend.layout.options.examples.setoptionsconfig">
  155. <title>Using setOption() and setConfig()</title>
  156. <para>
  157. Sometimes you need to configure the <classname>Zend_Layout</classname>
  158. object after it has already been instantiated;
  159. <methodname>setOptions()</methodname> and <methodname>setConfig()</methodname> give
  160. you a quick and easy way to do so:
  161. </para>
  162. <programlisting language="php"><![CDATA[
  163. // Using an array of options:
  164. $layout->setOptions($options);
  165. // Using a Zend_Config object:
  166. $layout->setConfig($options);
  167. ]]></programlisting>
  168. <para>
  169. Note, however, that certain options, such as
  170. <property>pluginClass</property> and <property>helperClass</property>, will have
  171. no affect when passed using this method; they need to be passed
  172. to the constructor or <methodname>startMvc()</methodname> method.
  173. </para>
  174. </example>
  175. <example id="zend.layout.options.examples.accessors">
  176. <title>Using Accessors</title>
  177. <para>
  178. Finally, you can also configure your <classname>Zend_Layout</classname>
  179. instance via accessors. All accessors implement a fluent
  180. interface, meaning their calls may be chained:
  181. </para>
  182. <programlisting language="php"><![CDATA[
  183. $layout->setLayout('foo')
  184. ->setLayoutPath('/path/to/layouts')
  185. ->setContentKey('CONTENT');
  186. ]]></programlisting>
  187. </example>
  188. </sect2>
  189. </sect1>
  190. <!--
  191. vim:se ts=4 sw=4 et:
  192. -->