I should just be able to return the response and not have to emit it in the controller manually
I should be able to just return response from the controller.
Hello and welcome to our forums!
Unfortunately, the information on your project is a bit sparse, so forgive me if I’m wrong.
If you mean a controller in a laminas-mvc based application then you do not need and can not use the laminas-httphandlerrunner component.
Use laminas-mvc-middleware instead if you want work with middleware and request handlers:
Hi froschdesign,
I figured out that httphandlerunner works differently.
However, my problem is that we have mvc application. Current the download action emits the headers and content using native php functions.
I am from Symfony world so would like to return a Response from the controller.
for example - StreamedResponse in symfony.
How we return a stream download in Laminas MVC? I am providing the output to the user as a spreadsheet file which I am creating.
Really appreciate your opinion and guidance.
Kind regards
Monty Panday
Hey there, allow me to chime in:
How we return a stream download in Laminas MVC? I am providing the output to the user as a spreadsheet file which I am creating.
There’s Laminas\Http\Response\Stream
, which I am using like this, in a controller action:
// get path to file, mimetype, file size and others beforehand
$response = $this->getResponse();
// add response headers here
stream = StreamResponse::fromStream($response->toString(), fopen($path, "r"));
return $stream;
StreamResponse
is imported like this:
use Laminas\Http\Response\Stream as StreamResponse;
Hope this helps