I am new to Zend Framework 2 and only know a little basics. I find it difficult to find a lot of examples as well.
Quesiton: Get BLOB field in database and display it through a controller. For example: http://www.mysite.com/images/2 will retrieve a BLOB from the database and display it to the user as an image so an html tag like <img src="http://www.mysite.com/images/2"/> will display an image.
I normally do it in ASP.NET MVC but have no clue how to do it here. I would be delighted if some one could enlighten me on how to achieve it.
Assume that I have fetched the image from the database.
I managed to find how to return JSON and believe some thing simple like that would work. But couldn’t find the solution. I will also need to send files like that.
public function displayAction()
{
$id = 10;
$albumImage = $this->getAlbumImageTable()->getAlbumImage($id);
if ($albumImages){
//Show the image $albumImage
//return JsonModel(array(...)) for json but for image ???
} else{
//Show some other image
}
}
I would be obliged if some one could help.
Thanks in advance.
As of Zend Framework 2.0 to 2.1
If you want to return an image, simply return the response object filled in with the content: that will tell the
Zend\Mvc\Applicationto entirely skip theZend\Mvc\MvcEvent::EVENT_RENDERevent and go toZend\Mvc\Application::EVENT_FINISHThis will cause the application to short-circuit to the
Zend\Mvc\Event::EVENT_FINISH, which in turn is capable of sending the response to the output.