Since it is only "filename cosmetics" we dont need to add this second passed param to our method: public function view($id = null) I found a pretty well working workaround: $this->Html->link('View as PDF', array('action'=>'view', 'ext'=>'pdf', 1, 'invoice-_some_customer_tag')) Īs you can see we simply add our filename to the url – after the id (!). Ok, but nobody wants his invoice to be "1.pdf". I did some research: Thats a well known browser deficiency that nobody yet fixed. In the above example it would be "1.pdf". They will be saved with the name in the url instead. But during my tryouts I found out that files served inline (Content-Disposition: inline filename="…") will not use the given filename on save. Note: If your browser does not understand the file format (in this case pdf) it will probably trigger the download right away. If you want this, though, you need to call $this->response->download($filename) in your controller action. So the browser will usually not force you to download it. Since we use the RequestHandler Component cake automatically detects that this will be a pdf file, it willĪ) set the correct header (application/pdf)ī) will try to find the specific pdf view in /View/Invoices/pdf/index.ctp and the pdf layout in /View/Layouts/pdf/default.ctpįiles like pdf can be displayed inline. Now, we set a link in the view to the file like so: $this->Html->link('View as PDF', array('action'=>'view', 'ext'=>'pdf', 1)) Let’s say you want to display an invoice as pdf. This will be an important part in the following auto-magic. ![]() Setupĭon’t forget to add the RequestHandler to your Controller components list: public $components = array('RequestHandler') That tells cake that urls ending with ".xyz" will be served as files (either inline or as download attachment). ![]() In your routes.php you need to add Router::parseExtensions() (or only specific ones). Skip this, if you want to cut to the chase. But as I just played around with it in 2.0, I will stick to that version for examples. Actually, its not that different in Cake1.3.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |