Zend Framework: Module Specific Layout Plugin

Gra­ham Ander­son posted an use­ful workaround for the mod­ule spe­cific lay­out prob­lem;
The default lay­out plu­gin will accept a stack of paths in LIFO order.
This allows a very sim­ple hack to always ensure that any mod­ule can have it’s own default lay­out which will auto­mat­i­cally over­ride the default mod­ule layout.


class App_Controller_Plugin_Layout extends Zend_Controller_Plugin_Layout {

pub­lic func­tion __construct ($lay­out = null)
{
parent::__construct ($lay­out);
}

pub­lic func­tion preDispatch(Zend_Controller_Request_Abstract $request)
{
// Insert cur­rent mod­ule lay­out dir to to overide any default lay­outs
if ( $request->getModuleName() != ‘default’ ) {

$lay­out­Path = APPLICATION_PATH . ‘/modules/’ .
$request->getModuleName() . ‘/views/layouts’;

$paths = array();
$paths[] = $this->getLayout()->getViewScriptPath();
$paths[] = $layoutPath;

$this->getLayout()->setViewScriptPath($paths);
}
}
}

Ass­sum­ing you set the fol­low­ing appli­ca­tion con­fig value:


resources.layout.layout = "default"

Now any mod­ule with a default.phtml lay­out will over­ride the default mod­ule layout.

e.g APPLICATION_PATH/modules/foobar/views/layouts/default.phtml

Cheers the noo,
Graham

Tags: , , ,

1 Response to "Zend Framework: Module Specific Layout Plugin"

Leave a Comment

*

Get Adobe Flash playerPlugin by wpburn.com wordpress themes