Disable layout and modify HTTP response headers (Zend Framework)

Suppose you want to send an XML file or an image to a user. Your controller would need to disable the layout (if there is one enabled) and change its headers.

Example controller

<?php

class ExampleController extends Zend_Controller_Action {

    public function preDispatch() {
        $this->_helper->layout()->disableLayout();
        $this->getResponse()->setHeader('Content-type', 'text/plain');
    }

    public function init() {
    }

    public function indexAction() {
        // action body
    }

}

?>
This entry was posted in PHP and tagged , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?