Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-04-2008, 05:29 PM
Junior Member
 
Join Date: Oct 2008
Posts: 4
Question Disable layout for entire module

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-04-2008, 05:40 PM
Junior Member
 
Join Date: Oct 2008
Posts: 4
Default

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 Code:
$layout Zend_Layout::getMvcInstance(); 
in your plugins preDispatch() function and then you can do something like this:
PHP Code:
<?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)
    {
    }

}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-04-2008, 05:50 PM
Junior Member
 
Join Date: Oct 2008
Posts: 4
Default

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 Code:
$layout Zend_Layout::getMvcInstance();
$layout->headTitle()->prepend(SITE_TITLE);
$layout->headTitle()->setSeparator(' - '); 
and I get an error
Code:
Fatal error: Call to undefined method Zend_Layout::headTitle() in /*/library/Custom/Plugin/Dispatcher.php on line 16
What am doing wrong?

Last edited by Cypher : 10-04-2008 at 06:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-05-2008, 02:03 PM
Junior Member
 
Join Date: Oct 2008
Posts: 4
Default bump

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 Code:
    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;
        }
    } 
Hope this helps someone...

Last edited by Cypher : 10-05-2008 at 03:40 PM. Reason: found solution
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-31-2008, 10:47 AM
Junior Member
 
Join Date: Dec 2008
Posts: 1
Default

saved my day.. thank you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:10 AM.