Using Zend Framework, you can have views and layouts without any configurations. Every action on a Zend_Controller
needs an equivalent phtml
file. Example:
If you have a controller named BooksController, having actions index
, add
, edit
, delete
; each action requires a phtml file ex:
- views/scripts/books/index.html
- views/scripts/books/add.html
- views/scripts/books/edit.html
- views/scripts/books/delete.html
However, there are times when you need not to display the phtml file, or display different phtml with different action. Helper functions come in handy.
Zend_Controller_Action
has a helper called viewRenderer
which has useful methods for our view / layout / controller needs.
Disable layout
If you are using layout on your project, but some pages requires no layout (ex: ajax call), you can disable layout by:
// This is inside the action of a certain controller $this->getHelper('layout')->disableLayout();
Set Different View (phtml) on an Action
To set a different view(phtml file) on an action, use the code below:
// Render 'foo' instead of current action script $this->_helper->viewRenderer('foo');
Disable automatic view rendering
If you don’t want to use a phtml
file as view or you simply want to disable view rendering, you may write:
$this->_helper->viewRenderer->setNoRender();
Source: http://framework.zend.com/manual/en/zend.controller.actionhelpers.html