2012/7/13 Demian Katz
<[hidden email]>
My application has a controller which renders images on the fly. I don't see an obvious, pre-existing way to do this with the ZF2 view functionality.
Do I need to build an ImageRenderer and ImageStrategy in order to make this happen, or is there a simpler way? It seems like a lot of infrastructure to build just to set some HTTP headers and dump out a blob of image data.
If there's a simple solution, I'd love to hear about it. If not, I'll be happy to share whatever I end up building; this seems like a fairly common use case that may be useful to have supported out of the box.
- Demian
If you return a Response object from your controller, no view rendering is involved. For example:
public function ImageAction()
{
$image = $this->doSomeRendering();
$response = $this->getResponse();
$response->setContent($image);
return $response;
}
You might want to set additional headers before the response is returned. You can do this by:
$headers = $response->getHeaders();
$headers->addHeaderLine('Some-Header', 'value-here');
--
Jurian Sluiman