tags:

views:

28

answers:

1

I am making a controller that will be responsible for a bunch of actions and I don't want to have to create a view file for each one, sometimes i just want to output strings.

I could just do echo 'Hello World'; die(); into the action. but is there a more correct way to do this?

+2  A: 

Yes, in the controller you can disable view rendering like this:

$this->getHelper('viewRenderer')->setNoRender();

And you add whatever you like to the output like this:

$this->getResponse()->setBody('Hello Moak!');

There are other things you can do with the Response object too:

$r = $this->getResponse();
$r->setHeader('Content-type', 'text/html', true);
$r->setRawHeader('HTTP/1.1 200 OK');
$r->setHttpResponseCode(200);
$r->clearBody();
$r->setBody('<html><h1>Hello</h1></hello>');
Adam
Great! Added `$this->_helper->layout()->disableLayout();` - thanks for the extra info on the response object
Moak