Created
July 1, 2011 04:53
-
-
Save jimbojsb/1057888 to your computer and use it in GitHub Desktop.
Module-specific layouts in Zend Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Genoa_Controller_Plugin_SwitchLayout extends Zend_Controller_Plugin_Abstract | |
{ | |
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) | |
{ | |
$module = $request->getModuleName(); | |
$layoutName = $module; | |
$layoutPath = APPLICATION_PATH . "/modules/$module/views/layouts"; | |
Zend_Layout::startMvc(); | |
$layout = Zend_Layout::getMvcInstance(); | |
$layout->setLayout($layoutName); | |
$layout->setLayoutPath($layoutPath); | |
} | |
} |
Maybe try to add layoutPath and layoutName into configuration, it will be better - for example in that case 3 modules can share one layout.
Yeah definitely. In this case, I didn't want them to share a layout. I could do one big layout folder though in case they needed to share one but also have separate ones
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sets the default layout based on what module is about to be dispatched. Assumes that you will have a layout named the same as your module, but easy to change that to just be "layout" or similar.