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.