<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.layout.options">
    <title>Zend_Layout Configuration Options</title>

    <para>
        <classname>Zend_Layout</classname> has a variety of configuration options. These
        may be set by calling the appropriate accessors, passing an array or
        <classname>Zend_Config</classname> object to the constructor or
        <code>startMvc()</code>, passing an array of options to
        <code>setOptions()</code>, or passing a <classname>Zend_Config</classname> object
        to <code>setConfig()</code>.
    </para>

    <itemizedlist>
        <listitem><para>
                <emphasis>layout</emphasis>: the layout to use. Uses the
                current inflector to resolve the name provided to the
                appropriate layout view script. By default, this value is
                'layout' and resolves to 'layout.phtml'. Accessors
                are <code>setLayout()</code> and <code>getLayout()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>layoutPath</emphasis>: the base path to layout view
                scripts. Accessors are <code>setLayoutPath()</code> and
                <code>getLayoutPath()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>contentKey</emphasis>: the layout variable used for
                default content (when used with the MVC). Default value is
                'content'. Accessors are <code>setContentKey()</code> and
                <code>getContentKey()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>mvcSuccessfulActionOnly</emphasis>: when using the
                MVC, if an action throws an exception and this flag is true, the
                layout will not be rendered (this is to prevent double-rendering
                of the layout when the <link linkend="zend.controller.plugins.standard.errorhandler">ErrorHandler
                plugin</link> is in use). By default, the flat is true.
                Accessors are <code>setMvcSuccessfulActionOnly()</code> and
                <code>getMvcSuccessfulActionOnly()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>view</emphasis>: the view object to use when
                rendering. When used with the MVC, <classname>Zend_Layout</classname> will
                attempt to use the view object registered with <link
                    linkend="zend.controller.actionhelpers.viewrenderer">the
                    ViewRenderer</link> if no view object has been passed to it
                explicitly. Accessors are <code>setView()</code> and
                <code>getView()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>helperClass</emphasis>: the action helper class to use
                when using <classname>Zend_Layout</classname> with the MVC components. By
                default, this is
                <classname>Zend_Layout_Controller_Action_Helper_Layout</classname>.
                Accessors are <code>setHelperClass()</code> and
                <code>getHelperClass()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>pluginClass</emphasis>: the front controller plugin
                class to use when using <classname>Zend_Layout</classname> with the MVC
                components. By default, this is
                <classname>Zend_Layout_Controller_Plugin_Layout</classname>. Accessors
                are <code>setPluginClass()</code> and
                <code>getPluginClass()</code>.
        </para></listitem>

        <listitem><para>
                <emphasis>inflector</emphasis>: the inflector to use when
                resolving layout names to layout view script paths; see <link
                    linkend="zend.layout.advanced.inflector">the
                    <classname>Zend_Layout</classname> inflector documentation for more
                    details</link>. Accessors are <code>setInflector()</code>
                and <code>getInflector()</code>.
        </para></listitem>
    </itemizedlist>

    <note>
        <title>helperClass and pluginClass must be passed to startMvc()</title>

        <para>
            In order for the <code>helperClass</code> and
            <code>pluginClass</code> settings to have effect, they must be
            passed in as options to <code>startMvc()</code>; if set later, they
            have no affect.
        </para>
    </note>

    <sect2 id="zend.layout.options.examples">
        <title>Examples</title>

        <para>
            The following examples assume the following <code>$options</code>
            array and <code>$config</code> object:
        </para>

        <programlisting role="php"><![CDATA[
$options = array(
    'layout'     => 'foo',
    'layoutPath' => '/path/to/layouts',
    'contentKey' => 'CONTENT',           // ignored when MVC not used
);
]]></programlisting>

        <programlisting role="php"><![CDATA[
/**
[layout]
layout = "foo"
layoutPath = "/path/to/layouts"
contentKey = "CONTENT"
*/
$config = new Zend_Config_Ini('/path/to/layout.ini', 'layout');
]]></programlisting>

        <example id="zend.layout.options.examples.constructor">
            <title>Passing options to the constructor or startMvc()</title>

            <para>
                Both the constructor and the <code>startMvc()</code> static
                method can accept either an array of options or a
                <classname>Zend_Config</classname> object with options in order to
                configure the <classname>Zend_Layout</classname> instance.
            </para>

            <para>
                First, let's look at passing an array:
            </para>

            <programlisting role="php"><![CDATA[
// Using constructor:
$layout = new Zend_Layout($options);

// Using startMvc():
$layout = Zend_Layout::startMvc($options);
]]></programlisting>

            <para>
                And now using a config object:
            </para>

            <programlisting role="php"><![CDATA[

$config = new Zend_Config_Ini('/path/to/layout.ini', 'layout');

// Using constructor:
$layout = new Zend_Layout($config);

// Using startMvc():
$layout = Zend_Layout::startMvc($config);
]]></programlisting>

            <para>
                Basically, this is the easiest way to customize your
                <classname>Zend_Layout</classname> instance.
            </para>
        </example>

        <example id="zend.layout.options.examples.setoptionsconfig">
            <title>Using setOption() and setConfig()</title>

            <para>
                Sometimes you need to configure the <classname>Zend_Layout</classname>
                object after it has already been instantiated;
                <code>setOptions()</code> and <code>setConfig()</code> give you
                a quick and easy way to do so:
            </para>

            <programlisting role="php"><![CDATA[
// Using an array of options:
$layout->setOptions($options);

// Using a Zend_Config object:
$layout->setConfig($options);
]]></programlisting>

            <para>
                Note, however, that certain options, such as
                <code>pluginClass</code> and <code>helperClass</code>, will have
                no affect when passed using this method; they need to be passed
                to the constructor or <code>startMvc()</code> method.
            </para>
        </example>

        <example id="zend.layout.options.examples.accessors">
            <title>Using Accessors</title>

            <para>
                Finally, you can also configure your <classname>Zend_Layout</classname>
                instance via accessors. All accessors implement a fluent
                interface, meaning their calls may be chained:
            </para>

            <programlisting role="php"><![CDATA[
$layout->setLayout('foo')
       ->setLayoutPath('/path/to/layouts')
       ->setContentKey('CONTENT');
]]></programlisting>
        </example>
    </sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->
