Outputting Content Directly

If you want to output content directly (rather than sending JSON or returned the user back to the web site), you can do so.

Firstly, you must set the driver to not return back to the web site (covered earlier in this chapter).

Next, you must access the HTTP response using $this->getResponse(). This returns an object that extends from Zend_Controller_Response_Abstract. Refer to http://framework.zend.com/manual/en/zend.controller.response.html for more details.

Call the setBody() method on the response object to set the body to return. You can also set any headers as required (this can be useful for sending back files, such as generated PDF files).