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
delete; each action requires a phtml file ex:
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.
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: