Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


The following examples assume the following $options array and $config object:

= array(
'layout'     => 'foo',
'layoutPath' => '/path/to/layouts',
'contentKey' => 'CONTENT',           // ignored when MVC not used
layout = "foo"
layoutPath = "/path/to/layouts"
contentKey = "CONTENT"
$config = new Zend_Config_Ini('/path/to/layout.ini''layout');

Example 509. Passing options to the constructor or startMvc()

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

First, let's look at passing an array:

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

// Using startMvc():
$layout Zend_Layout::startMvc($options);

And now using a config object:

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

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

// Using startMvc():
$layout Zend_Layout::startMvc($config);

Basically, this is the easiest way to customize your Zend_Layout instance.

Example 510. Using setOption() and setConfig()

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

// Using an array of options:

// Using a Zend_Config object:

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

Example 511. Using Accessors

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


Zend Framework