Thursday, October 27, 2011

Re: Own layouts and content-type

well, it seems like it is possible to do from a controller action:
http://book.cakephp.org/2.0/en/controllers/request-response.html?highlight=response

$this->response->type($file['type']);
$this->response->download($file['name']);
$this->response->body($file['content']);
$this->response->send();

but if the layout itself could do that, it would be nice, too.
does it have access to the response?

the only other way would be a specific PdfView, I guess.
But that I really want to avoid. Otherwise I end up with hundreds of
of Views
containing the same code except for the different content-type...

a layout used to be the best solution so far:

<?php
$charset = Configure::read('App.encoding');
header('Content-Type: application/pdf; charset=' . $charset);
echo $content_for_layout;
?>


On 27 Okt., 11:43, euromark <dereurom...@googlemail.com> wrote:
> this seems to be left undocumented
> but cake2.0 seems to automatically output a content-type which
> overrides the own one
>
> in 1.3 I had in the "pdf" layout:
> header('Content-Type: application/pdf; charset=' . $charset);
> ...
>
> now in 2.0 it always is "text/html"
> after debugging I assume that the CakeReponse send() is responsable
> for that
> But it does not say how to override it (or set the content type
> correctly in 2.0)

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: