15

I have the following controller that, among other methods it has this one:

class EquipasController extends OccControllerAction {

    public function listaAction()
    {    
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
    }
}

I was expecting that, when I do: http://www.example.com/equipas/lista/

the controller will execute and I will see no layout rendering on my viewport.

However, that's not the case. I get my home page rendered.

Where on ZF do we normally say: if an action doesn't exist a home page should appear?

Note: If, instead of: http://www.example.com/equipas/lista/

I do, http://www.example.com/equipas/adasdas21232131/ that doesn't exist.

I get the same home page rendering.

What could be the cause for such a behaviour?

A Zend Newbie, MEM

Cœur
  • 37,241
  • 25
  • 195
  • 267
MEM
  • 30,529
  • 42
  • 121
  • 191
  • Something wrong with my question? Should I provide more details? Am I saying something dummy? Please let me know. Stuck here. – MEM Nov 26 '10 at 19:17
  • Could you specify your problem? Do you want to disable the layout or do you want redirect to the homepage when an action doesn't exist? – Nedec Nov 26 '10 at 19:50
  • Thanks. No. I don't want to disable the layout nor redirect to homepage when the action doesn't exist. What I want is, when we do: http://www.mysite.com/equipas/lista/ (SO, when we call the action lista) the layout isn't used. Why? For ajax calls for example. Thanks. – MEM Nov 26 '10 at 20:26
  • Solved. We also must enable that action on Acl. Otherwise nothing will run on it, hence, the layout will NOT disable. – MEM Nov 27 '10 at 00:18

3 Answers3

23

Add this inside your controller:

public function preDispatch(){
        $this->_helper->layout()->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender(true);
    }
liding
  • 752
  • 9
  • 21
5

This may not answer your question directly (which you seem to have solved anyway), but to disable the layout and deliver a different view for AJAX requests, consider using the AjaxContext action helper.

Phil
  • 157,677
  • 23
  • 242
  • 245
0

in zf2

 public function indexAction()
    {    
        echo "json"
        return $this->getResponse();
    }
Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78