Wednesday, June 11, 2014

Re: Use CakeResponse in Helper.

Didn't know Savant had a csv plugin. Good to know, although we usually export to excel.

On Wednesday, 11 June 2014 12:43:55 UTC+2, euromark wrote:
Why are you using a view/helper for this?
Use https://github.com/josegonzalez/cakephp-csvview then you have the full response object available directly in the action.
And no template needed, as the view class itself is responsable for directly transforming the array into the CSV structure.


Am Mittwoch, 11. Juni 2014 00:49:58 UTC+2 schrieb gloop:
Hello i try to write an helper to create and download a CSV.

Now i have the problem to set the type in the helper.

I try:

function renderHeaders() {
    $response = new CakeResponse(array(
       'type' => 'csv'
    ));
    $response->download($this->filename);
    $response->send();
}

Now i can download the file, but it's always type "text/html".

When i set in the controller $this->response->type('csv'); it works correct.

Is there a way to use the CakeResponse in the Helper?

Kind Regards
Steffen
 

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: