You were an excellent partner in every way. You delivered your commitments on time, you provided clear guidance on what you needed from me, why you needed it, and when my communication was not sufficient you asked for clarification.



Blazing a trail to better facilities management.

Configuring Zend_Layout pluginClass

The Zend 1 approved way to switch the layout renderer is the pass the pluginClass parameter to Zend_Layout.  Internally, Zend instantiates the class and passes only the layout to it.  But what if you want your renderer to be configurable?  There's no built-in way to pass configuration options to the plugin class, so the class has to roll its own.

Recently, I did just that: my custom renderer checks to see if the routed module has a layout override and, if so, switches to that.  But I wanted this behavior to be configurable, because not all applications have that need.  There's certainly more than one way to do this, but the method I chose was to look up the application options inside my custom class.  Here's how.

In your application configuration, setup the values:

# application.ini
resources.layout.layout = default
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.layout.pluginClass = "My_Controller_Plugin_Layout" ; the plugin class Zend will instantiate
resources.layout.pluginConfig.useModuleLayout = false        ; the plugin configuration I want to pass

Now, in your custom layout plugin:


class My_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        $config = nwe Zend_Config(Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions());

        // if we want to allow module's to have their own layout
        if ($config->->resources->layout->pluginConfig->useModuleLayout) {
            // do whatever


Voila! You now have a configurable custom Zend_Layout plugin class.

Trackback URL for this post:

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.