Zend Framework – Disable Layout and View from Rendering (Handy for AJAX)

///Zend Framework – Disable Layout and View from Rendering (Handy for AJAX)

Zend Framework – Disable Layout and View from Rendering (Handy for AJAX)

I don’t know how many times I have needed to look this up for myself, typically when I am putting together a controller action that I want to use specifically for outputting something like JSON for some AJAX related thing I am doing. That or when I am working on a page that I need to have different from the base template that I have setup in my layouts. Either way, figured I’d post it here like the rest of the code I tend to reuse often, and share with the world cause they may be looking for it too.\r\n\r\n
\r\npublic function indexAction() \r\n{ \r\n    $this->_helper->layout()->disableLayout();\r\n    $this->_helper->viewRenderer->setNoRender(true);\r\n}\r\n
\r\n\r\nThe two above lines added into just about any “Action” will stop your default layout from loading. Alternatively you could also do it as a pre dispatch for the entire controller like so.\r\n\r\n
\r\npublic function preDispatch()\r\n{\r\n    $this->_helper->layout()->disableLayout();\r\n    $this->_helper->viewRenderer->setNoRender(true);\r\n}\r\n
By | 2014-01-05T10:16:54+00:00 September 25th, 2012|PHP|1 Comment

About the Author:

Not much to know about me, I'm a 35+ year old coder, geek, gamer..

One Comment

  1. Valencia April 28, 2013 at 5:14 am

    Awesome! Its genuinely awesome piece of writing, I have got much clear idea on the topic of from this article.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: