Use the response class to set the headers from the controller: http://book.cakephp.org/2.0/en/controllers/request-response.html#CakeResponse::type
Am Donnerstag, 22. August 2013 13:45:58 UTC+2 schrieb Adrian Tello: > > The header tags should be used in the controller, not in the view. > El 20/08/2013 22:25, "Gray McCord" <[email protected] <javascript:>> > escribió: > >> I've been using PHP for a while, but am new to Cake. What I am attempting >> to do is create a vCard on the fly in a PHP variable and download it to a >> client. To do that, I need to set the response header to something like >> "Content-Type: text/x-vcard; charset=utf-8" and then add a >> 'Content-Disposition: attachment ; filename=\"vcardname.vcf\" ' header. I >> have done this successfully in standalone PHP by just using the "header" >> function, but it seems that no matter what I do, the CakePHP view just >> displays the vCard in text and sets the content type to text/html. >> >> I've been Googling and reading for a couple of days and have not made any >> progress. I freely admit that I'm probably missing something basic, but I >> just can't figure out what. >> >> My download.ctp view file looks like this: >> >> ....Some code to make a vcard from a DB record in $vcard >> >> header("Content-Type: text/x-vcard; charset=utf-8"); >> header("Content-Disposition: attachment; filename=\"vcardname.vcf\";"); >> echo $vcard; >> >> Pretty basic. If I run this code as a standalone PHP script, it >> downloads the file to my browser as expected. When I run it as a Cake view >> tied to a controller action, it just echoes the vcard variable to the >> screen and leaves the content type as text/html. >> >> Any advice would be greatly appreciated! >> >> Thanks, >> >> Gray >> >> -- >> Like Us on FaceBook https://www.facebook.com/CakePHP >> Find us on Twitter http://twitter.com/CakePHP >> >> --- >> You received this message because you are subscribed to the Google Groups >> "CakePHP" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/cake-php. >> For more options, visit https://groups.google.com/groups/opt_out. >> > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
