Zend Framework

Zend Framework Tips: View and Layout Settings

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

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

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:


Source: http://framework.zend.com/manual/en/zend.controller.actionhelpers.html

Leave a reply

Your email address will not be published. Required fields are marked *