I’m currently working on loading a different layout file per module.
I have added the following to my config.ini file
; Module Support
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
; Module-based Layout Support
resources.layout.pluginClass= "Layout_Plugin_ModuleLayout"
And the following Controller Plugin:
class Layout_Plugin_ModuleLayout extends Zend_Layout_Controller_Plugin_Layout {
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$this->getLayout()->setLayoutPath(
Zend_Controller_Front::getInstance()
->getModuleDirectory($request->getModuleName()) . '/layouts'
);
$this->getLayout()->setLayout('layout');
}
}
Everything works fine, but I would prefer to register this plugin in the bootstrap file along with the other plugins. When I move this plugin to the Bootstrap file and register it like this:
protected function _initLayouts() {
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Layout_Plugin_ModuleLayout());
}
I get the following error:
Fatal error: Call to a member function setLayoutPath() on a non-object in C:\workarea\web_projects\gam\trunk\website\library\Layout\Plugin\ModuleLayout.php on line 31
Obviously, I’m doing something wrong or have misunderstood how this plugin works.
EDIT: Eventually used a modified version of the solution at http://dustint.com/post/28/per-module-zend_layout. However I’m open to suggestions about this. This solution uses a normal controller plug, whereas I suspect that I should be making us of the layout plugin type. However, it worked.
Eventually used a modified version of the solution at http://dustint.com/post/28/per-module-zend_layout.