Zend_Layout-Options.xml 8.4 KB

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