https://github.com/zendframework/zf2/issues/2651

Cheers,
David

On 02/10/12 23:04, Matthew Weier O'Phinney wrote:
David --

Can you report this issue at https://github.com/zendframework/zf2/issues
please?

-- David Muir <[email protected]> wrote
(on Tuesday, 02 October 2012, 12:51 PM +1000):
I tried using the stream and phpEnvironment responses, but nothing
gets returned.

eg:
$response = new \Zend\Http\Response\Stream();
$response->getHeaders()->addHeaders(array(
     'Content-type' => 'image/jpg'
));
$response->setStream(fopen($cachedFile, 'r'));
return $response;

Just to confirm, the following works:
$fh = fopen($cachedFile, 'r');
header('Content-type: image/jpg');
fpassthru($fh);
exit;

Seems that the view renderer is indeed skipped, but the response
object doesn't actually get output.
The headers that show up in firebug are what I'd expect from a
normal html response:

Connection    Keep-Alive
Content-Encoding    gzip
Content-Type    text/html
Date    Tue, 02 Oct 2012 02:47:59 GMT
Keep-Alive    timeout=5, max=99
Transfer-Encoding    chunked
Vary    Accept-Encoding

Using ZF 2.0.2

Cheers,
David



On 01/10/12 17:49, Marco Pivetta wrote:
Hi there!
I wouldn't directly return an output within your controllers.
Instead, you can return a Response object, which will already tell the MVC
to skip the 'render' (view) step:

a) fill a response object with some content you fetch from a file (not
really fast):

     public function indexAction()
     {
         $response = new \Zend\Http\PhpEnvironment\Response();
         $response->setThis();
         $response->setThat();
         $response->setMore();
         $response->setContent(file_get_contents('path/to/file.txt'));
         return $response;
     }

b) use a stream response

     public function indexAction()
     {
         $response = new \Zend\Http\Response\Stream();
         $response->setThis();
         $response->setThat();
         $response->setMore();
         $response->setStream(fopen('path/to/file.txt', 'r'));
         return $response;
     }


Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com



On 1 October 2012 09:21, David Muir-2 [via Zend Framework Community] <
[email protected]> wrote:

What's the best way to output a file from one of my controllers?

Cheers,
David

--
List: [hidden email]<http://user/SendEmail.jtp?type=node&node=4657245&i=0>
Info: http://framework.zend.com/archives
Unsubscribe: [hidden 
email]<http://user/SendEmail.jtp?type=node&node=4657245&i=1>




------------------------------
  If you reply to this email, your message will be added to the discussion
below:

http://zend-framework-community.634137.n4.nabble.com/ZF2-outputting-files-tp4657245.html
  To start a new topic under Zend Framework, email
[email protected]
To unsubscribe from Zend Framework Community, click 
here<http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=634137&code=b2NyYW1pdXNAZ21haWwuY29tfDYzNDEzN3wxNzE0OTI1MTk4>
.
NAML<http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF2-outputting-files-tp4657245p4657248.html
Sent from the Zend Framework mailing list archive at Nabble.com.

--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]




--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to