![]() |
|
|||
|
Hi all,
I've been using framework for quite a long time and now I want start using Zend_Layout to tidy up my code. I have several modules including default and ajax. What I need to do is change (or disable) layouts per module. For example, I would like to use different layout for all my ajax module (basically all ajax controllers/actions). Also I would like to assign different stylesheets and javascripts to different modules as well as set different headTitle for specific modules and do other stuff that I would otherwise do in a controller or a .phtml file. I've spent entire day today trying to understand how to do it to no avail. It's driving me crazy and that's why out of despair I am asking for your help ![]() Can anyone either explain how to do it or point me to some nice tutorials that explain exactly this? Thanks in advance! |
|
|||
|
Gosh, sometimes one has to ask a question to find an answer himself...
Two minutes after I posted the topic, I found an explanation here: Per Module Zend_Layout | Views From The Hill You can do it by calling [PHP]$layout = Zend_Layout::getMvcInstance();[/PHP] in your plugins preDispatch() function and then you can do something like this: [PHP] <?php class Custom_Plugin_Dispatcher extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); $layout = Zend_Layout::getMvcInstance(); switch ($controller) { case 'index': // use default layout specified in your bootstrap break; case 'ajax': $layout->setLayout('ajax'); break; case 'error: $layout->setLayout('error'); break; default: $layout->disableLayout(); break; } } public function postDispatch(Zend_Controller_Request_Abstract $request) { } } ?> [/PHP] |
|
|||
|
Hmm, nevertheless, I still have a question: how can I set things like headTitle() in the preDispatch function?
I am trying to do this: [PHP] $layout = Zend_Layout::getMvcInstance(); $layout->headTitle()->prepend(SITE_TITLE); $layout->headTitle()->setSeparator(' - '); [/PHP] and I get an error Code:
Fatal error: Call to undefined method Zend_Layout::headTitle() in /*/library/Custom/Plugin/Dispatcher.php on line 16 Last edited by Cypher; 10-04-2008 at 06:11 PM. |
|
|||
|
This turned out to be my own monologue
![]() Luckily I found a solution myself again by reading Zend/Layout.php file. Here's how my preDispatch function looks now: [PHP] public function preDispatch(Zend_Controller_Request_Abstract $request) { $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); $layout = Zend_Layout::getMvcInstance(); $layout->getView()->headTitle()->prepend(SITE_TITLE); $layout->getView()->headTitle()->setSeparator(' - '); switch ($module) { case 'default': break; case 'ajax': $layout->disableLayout(); break; default: break; } } [/PHP] Hope this helps someone... Last edited by Cypher; 10-05-2008 at 03:40 PM. Reason: found solution |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |