How to skip view / layout in zf controller

I create a controller that will be responsible for a bunch of actions, and I do not want to create a presentation file for each of them, sometimes I just want to output lines.

I could just do echo 'Hello World'; die();in action. but is there a better way to do this?

+3
source share
1 answer

Yes, in the controller you can turn off the view visualization as follows:

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

And you add whatever you like to the weekend:

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

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

$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>');
+2
source

Source: https://habr.com/ru/post/1757269/


All Articles