+ Reply to Thread
Results 1 to 5 of 5

Thread: Disable layout for entire module

  1. #1
    Cypher is offline 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!

  2. #2
    Cypher is offline 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]$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]

  3. #3
    Cypher is offline 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]
    $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
    What am doing wrong?
    Last edited by Cypher; 10-04-2008 at 06:11 PM.

  4. #4
    Cypher is offline 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]
    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

  5. #5
    rlaszlo is offline Junior Member
    Join Date
    Dec 2008
    Posts
    1

    Default

    saved my day.. thank you!

+ Reply to Thread

Similar Threads

  1. Populating layout variable in each module
    By knave in forum Model-View-Controller (MVC)
    Replies: 0
    Last Post: 03-08-2010, 03:13 PM
  2. Change Layout according to the Module
    By mm.sour in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 02-10-2010, 09:57 AM
  3. Layout Changing according to Module change
    By anindya in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 10-28-2009, 11:24 PM
  4. Disable Layout for Ajax Requests
    By simon2807 in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 02-15-2009, 08:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts