Dynamic Module-based Layout Picker
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 2526 27 28 29 3031 32 33 34 3536 37 38 39 | <?php class Plugin_ModuleLayout extends Zend_Controller_Plugin_Abstract { /** * preDispatch function. * * Define the layout path based on what module is being used. * * @author Aaron (bachya1208[at]googlemail.com) * @access public * @param Zend_Controller_Request_Abstract $request * @return void */ public function preDispatch(Zend_Controller_Request_Abstract $request) { $module = strtolower($request->getModuleName()); $layout = Zend_Layout::getMvcInstance(); if ($layout->getMvcEnabled()) { $layout->setLayoutPath(APPLICATION_PATH . '/modules/' . $module . '/layouts/'); $layout->setLayout($module); } }} ## In bootstrap.php - <?php defined('APPLICATION_PATH') or define('APPLICATION_PATH', dirname(__FILE__)); ... Zend_Layout::startMvc(); $frontController->registerPlugin(new Plugin_ModuleLayout()); ?> |
Comments
How about a fall back to the default module layout in case their isn't a specific module layout?
Great!
But, what about controller/models.views?
I'm looking for a Plugin that handles with everything to put models to work
@davedevelopment: good idea - I'm kind of relying on people actually using my proposed directory structure. I'll make updates soon and repost.
@Fabio: I'm not sure I understand your question - you're looking for a directory structure where each module has its own controllers, models, and views?
couldn't you simply check if a layout file exists then setlayout?
I am currently only using 3 layouts (login, admin, public) and I simply setlayout for the login module (default is set in bootstrap).
I could see how (for example) a shop could use muliple layouts for index, category, product pages.
just my 2 cents
how do I make this with the 'latest version of the bootstrap ZendFrameworkQuickstart-20090430 ???
You must login before commenting on a snippet. If you do not have an account, please register.
Snippet description
Assuming a directory structure where each module has its own layout folder:
EXAMPLE:
/application/modules/default/layouts
/application/modules/admin/layouts
...
This plugin will determine which layouts folder to use based on which module is currently in use. Probably could be expanded/tightened up, so I'd love to hear your comments!
Snippet details
- Created:
-
bachya
- Edited:
-
bachya
- Revision Id:
- 33
- Edit Message:
- Initial Release
- Tags:
- module layout plugin
- Comments:
- 7
- Views:
- 2613
- Points:
- 0 (0 votes)
2 years ago
beautiful !