Zend_Layout-Options.xml 8.0 KB

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