Hi, it's my first post too :-)
In order to output a pdf, I do this in the action:
$response = $this->getResponse();
$response
->setHeader('Cache-Control', 'public', true)
->setHeader('Content-Description', 'File Transfer', true)
->setHeader('Content-Disposition', 'attachment;
filename='.$ref.'.pdf', true)
->setHeader('Content-Type', 'application/pdf', true)
->setHeader('Content-Transfer-Encoding', 'binary', true)
->appendBody($invoices->getPdf($id));
;
I think it's better not to break the MVC way to display anything.
Filip Wirefors a écrit :
Hi All! My first post here. More to come... ;)
I have a question regarding the MVC implementation and sending headers.
Say I write an action that should just output an image. An action that
can be used like this:
<img src="/module/controller/output/imgId/1529" alt="" />
Say I have a library class calld My_Image that does all the GD magic
to output an image.
Then I do this in my action controller:
function indexAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$img = new My_Image('/path/to/1529.jpg');
// ...
$img->outputToBrowser();
}
In this case the My_Image::outputToBrowser method sends all the
header()s that we need
to send and then stops the script execution with an exit;
Is this the correct way of doing this? Or should I rather send
the headers in the controller like...
$this->getResponse()->setHeader('Content-Type', 'image/jpeg');
// ...
$img->outputToBrowser();
.. and then let the dispatch loop continue?
Just need some advice on this, because I'm afraid that I miss out on
something if i send the
headers and exit on my own. Whats the best practice in this case?
Thanks in advance!
/Filip - from sweden
------------------------------------------------------------------------
Den perfekta mixen av nöjesnyheter & livekonserter! MSN Video
<http://video.se.msn.com/v/sv-se/v.htm>