Zend_Layout has a number of use cases for the advanced
developer who wishes to adapt it for different view implementations,
file system layouts, and more.
The major points of extension are:
Custom view objects.
Zend_Layout allows you to utilize any class that
Custom front controller plugins.
Zend_Layout ships with a standard front controller
plugin that automates rendering of layouts prior to returning
the response. You can substitute your own plugin.
Custom action helpers.
Zend_Layout ships with a standard action helper
that should be suitable for most needs as it is a dumb proxy
to the layout object itself.
Custom layout script path resolution.
Zend_Layout allows you to use your own inflector for layout
script path resolution, or simply to modify the attached
inflector to specify your own inflection rules.
Zend_Layout allows you to use any class implementing
Zend_View_Interface or extending
Zend_View_Abstract for rendering your layout script.
Simply pass in your custom view object as a parameter to the
startMvc(), or set it using the
$view = new My_Custom_View();
|Not all Zend_View implementations are equal|
If you need to use a custom
Alternately, if your view implementation supports any sort of plugin capability, you can access the variables via the 'Zend_Layout' placeholder, using the placeholder helper:
When used with the MVC components,
registers a front controller plugin that renders the layout as the
last action prior to exiting the dispatch loop. In most cases, the
default plugin will be suitable, but should you desire to write
your own, you can specify the name of the plugin class to load by
passing the pluginClass option to the
Any plugin class you write for this purpose will need to extend
Zend_Controller_Plugin_Abstract, and should accept a
layout object instance as an argument to the constructor. Otherwise,
the details of your implementation are up to you.
The default plugin class used is
When used with the MVC components,
registers an action controller helper with the helper broker. The
Zend_Layout_Controller_Action_Helper_Layout, acts as a
dumb proxy to the layout object instance itself, and should be
suitable for most use cases.
Should you feel the need to write custom functionality, simply write
an action helper class extending
Zend_Controller_Action_Helper_Abstract and pass the
class name as the helperClass option to the
startMvc() method. Details of the implementation are
up to you.
establish a filter chain for translating a layout name to a layout
script path. By default, it uses the rules 'Word_CamelCaseToDash'
followed by 'StringToLower', and the suffix 'phtml' to transform the
name to a path. As some examples:
'foo' will be transformed to 'foo.phtml'.
'FooBarBaz' will be transformed to 'foo-bar-baz.phtml'.
You have three options for modifying inflection: modify the
inflection target and/or view suffix via
accessors, modify the inflector rules and target of the inflector
associated with the
Zend_Layout instance, or create
your own inflector instance and pass it to
Ejemplo 40.4. Using Zend_Layout accessors to modify the inflector
Zend_Layout inflector uses static
references for the target and view script suffix, and
has accessors for setting these values.
// Set the inflector target:
// Set the layout view script suffix:
Ejemplo 40.5. Direct modification of Zend_Layout inflector
Inflectors have a target and one or more rules. The default
target used with
Zend_Layout is ':script.:suffix';
':script' is passed the registered layout name, while ':suffix'
is a static rule of the inflector.
Let's say you want the layout script to end in the suffix 'html', and that you want to separate MixedCase and camelCased words with underscores instead of dashes, and not lowercase the name. Additionally, you want it to look in a 'layouts' subdirectory for the script.
Ejemplo 40.6. Custom inflectors
In most cases, modifying the existing inflector will be enough.
However, you may have an inflector you wish to use in several
places, with different objects of different types.
Zend_Layout supports this.
$inflector = new Zend_Filter_Inflector('layouts/:script.:suffix');
':script' => array('Word_CamelCaseToUnderscore'),
'suffix' => 'html'
|Inflection can be disabled|
Inflection can be disabled and enabled using accessors on the