1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.layout.options">
4 <title>Zend_Layout Configuration Options</title>
7 <classname>Zend_Layout</classname> has a variety of configuration options. These
8 may be set by calling the appropriate accessors, passing an array or
9 <classname>Zend_Config</classname> object to the constructor or
10 <methodname>startMvc()</methodname>, passing an array of options to
11 <methodname>setOptions()</methodname>, or passing a <classname>Zend_Config</classname>
12 object to <methodname>setConfig()</methodname>.
18 <emphasis>layout</emphasis>: the layout to use. Uses the
19 current inflector to resolve the name provided to the
20 appropriate layout view script. By default, this value is
21 'layout' and resolves to 'layout.phtml'. Accessors
22 are <methodname>setLayout()</methodname> and <methodname>getLayout()</methodname>.
28 <emphasis>layoutPath</emphasis>: the base path to layout view
29 scripts. Accessors are <methodname>setLayoutPath()</methodname> and
30 <methodname>getLayoutPath()</methodname>.
36 <emphasis>contentKey</emphasis>: the layout variable used for
37 default content (when used with the <acronym>MVC</acronym>). Default value is
38 'content'. Accessors are <methodname>setContentKey()</methodname> and
39 <methodname>getContentKey()</methodname>.
45 <emphasis>mvcSuccessfulActionOnly</emphasis>: when using the
46 <acronym>MVC</acronym>, if an action throws an exception and this flag is
47 <constant>TRUE</constant>, the layout will not be rendered (this is to prevent
48 double-rendering of the layout when the <link
49 linkend="zend.controller.plugins.standard.errorhandler">ErrorHandler
50 plugin</link> is in use). By default, the flat is <constant>TRUE</constant>.
51 Accessors are <methodname>setMvcSuccessfulActionOnly()</methodname> and
52 <methodname>getMvcSuccessfulActionOnly()</methodname>.
58 <emphasis>view</emphasis>: the view object to use when rendering. When used with the
59 <acronym>MVC</acronym>, <classname>Zend_Layout</classname> will attempt to use the
60 view object registered with <link
61 linkend="zend.controller.actionhelpers.viewrenderer">the ViewRenderer</link> if
62 no view object has been passed to it explicitly. Accessors are
63 <methodname>setView()</methodname> and <methodname>getView()</methodname>.
69 <emphasis>helperClass</emphasis>: the action helper class to use
70 when using <classname>Zend_Layout</classname> with the <acronym>MVC</acronym>
71 components. By default, this is
72 <classname>Zend_Layout_Controller_Action_Helper_Layout</classname>.
73 Accessors are <methodname>setHelperClass()</methodname> and
74 <methodname>getHelperClass()</methodname>.
80 <emphasis>pluginClass</emphasis>: the front controller plugin
81 class to use when using <classname>Zend_Layout</classname> with the
82 <acronym>MVC</acronym> components. By default, this is
83 <classname>Zend_Layout_Controller_Plugin_Layout</classname>. Accessors
84 are <methodname>setPluginClass()</methodname> and
85 <methodname>getPluginClass()</methodname>.
91 <emphasis>inflector</emphasis>: the inflector to use when
92 resolving layout names to layout view script paths; see <link
93 linkend="zend.layout.advanced.inflector">the
94 <classname>Zend_Layout</classname> inflector documentation for more
95 details</link>. Accessors are <methodname>setInflector()</methodname>
96 and <methodname>getInflector()</methodname>.
102 <title>helperClass and pluginClass must be passed to startMvc()</title>
105 In order for the <code>helperClass</code> and
106 <code>pluginClass</code> settings to have effect, they must be
107 passed in as options to <methodname>startMvc()</methodname>; if set later, they
112 <sect2 id="zend.layout.options.examples">
113 <title>Examples</title>
116 The following examples assume the following <varname>$options</varname>
117 array and <varname>$config</varname> object:
120 <programlisting language="php"><![CDATA[
123 'layoutPath' => '/path/to/layouts',
124 'contentKey' => 'CONTENT', // ignored when MVC not used
128 <programlisting language="php"><![CDATA[
132 layoutPath = "/path/to/layouts"
133 contentKey = "CONTENT"
135 $config = new Zend_Config_Ini('/path/to/layout.ini', 'layout');
138 <example id="zend.layout.options.examples.constructor">
139 <title>Passing options to the constructor or startMvc()</title>
142 Both the constructor and the <methodname>startMvc()</methodname> static
143 method can accept either an array of options or a
144 <classname>Zend_Config</classname> object with options in order to
145 configure the <classname>Zend_Layout</classname> instance.
149 First, let's look at passing an array:
152 <programlisting language="php"><![CDATA[
153 // Using constructor:
154 $layout = new Zend_Layout($options);
157 $layout = Zend_Layout::startMvc($options);
161 And now using a config object:
164 <programlisting language="php"><![CDATA[
165 $config = new Zend_Config_Ini('/path/to/layout.ini', 'layout');
167 // Using constructor:
168 $layout = new Zend_Layout($config);
171 $layout = Zend_Layout::startMvc($config);
175 Basically, this is the easiest way to customize your
176 <classname>Zend_Layout</classname> instance.
180 <example id="zend.layout.options.examples.setoptionsconfig">
181 <title>Using setOption() and setConfig()</title>
184 Sometimes you need to configure the <classname>Zend_Layout</classname>
185 object after it has already been instantiated;
186 <methodname>setOptions()</methodname> and <methodname>setConfig()</methodname> give
187 you a quick and easy way to do so:
190 <programlisting language="php"><![CDATA[
191 // Using an array of options:
192 $layout->setOptions($options);
194 // Using a Zend_Config object:
195 $layout->setConfig($options);
199 Note, however, that certain options, such as
200 <code>pluginClass</code> and <code>helperClass</code>, will have
201 no affect when passed using this method; they need to be passed
202 to the constructor or <methodname>startMvc()</methodname> method.
206 <example id="zend.layout.options.examples.accessors">
207 <title>Using Accessors</title>
210 Finally, you can also configure your <classname>Zend_Layout</classname>
211 instance via accessors. All accessors implement a fluent
212 interface, meaning their calls may be chained:
215 <programlisting language="php"><![CDATA[
216 $layout->setLayout('foo')
217 ->setLayoutPath('/path/to/layouts')
218 ->setContentKey('CONTENT');