What about a view like this. I have not tested but extracted from a view in one project that is a little more complex but it is just as an example.
<?php Configure::write('debug', 0); $filename = "export.csv"; $delimiter = ","; $fields = array("id", "last", "fist", "email"); $newline = "\r\n"; header('Content-type: excel/'.$format); header('Content-Disposition: attachment; filename="'.$filename.'"'); // Write header fields name foreach( $fields as $v) { echo $v . $delimiter; } echo $newline; // Write data foreach($data as $row) { foreach($fields as $v) { echo $row['User'][$v] . $delimiter; } echo $newline; } ?> hth ________________________________ Da: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] Per conto di Gonzalo Servat Inviato: martedì 29 maggio 2007 22.59 A: cake-php@googlegroups.com Oggetto: Re: How to enable a CSV webservice? On 5/29/07, Howard Glynn <[EMAIL PROTECTED]> wrote: Slightly bad karma to reply to one's own post so soon, but after continuing to investigate, I'd like to provide a solution for the mail archives. I just didn't fully understand the route handling up until this point, but the light is starting to go on for me. I have subsequently found 2 ways it can be done: 1) Less agreeable way: change the cake distro libs/router.php around line 147, adding: $this->connect('/csv/:controller/:action/*', array('webservices' => 'Csv')); 2) More agreeable, add to the application app/config/routes.php $Route->connect('/csv/:controller/:action/*', array('webservices' => 'Csv')); I am well aware that CSV is not a webservice as such but I want the CSV output availability to be consistent with the XML approach. Is your requirement strictly CSV or can it be an actual Excel file? I found this article recently at bakery.cakephp.org (which I plan on using) to create an XLS file from database records: http://bakery.cakephp.org/articles/view/generate-excel-spreadsheets-from-you r-database <http://bakery.cakephp.org/articles/view/generate-excel-spreadsheets-from-yo ur-database> If it's strictly CSV what you need, then it won't help, but I think what klonae said is probably the simplest way. klonae: just wondering, shouldn't the header() calls be made just before the foreach begins? - Gonzalo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---