This may or may not help. it's not exactly what you want to do, but I
don't have much use for CSV. I needed to be able to allow site
managers to generate and download an excel spreasheet of user records
from the database.
In the controller:
function excel() {
$this->layout = 'excelfile';
$data = $this->Alum->findAll('', array('first_name', 'last_name',
'email'), 'last_name ASC');
$this->set('data', $data);
}
The excel.thtml view:
<?php
foreach($data as $record) {
echo $record['Alum']['first_name']."\t";
echo $record['Alum']['last_name']."\t";
echo $record['Alum']['email']."\n";
header("Content-type: application/msexcel");
header("Content-Disposition: attachment;
filename=all_alumni_names.xls");
}
?>
The excel layout file:
<?php echo $content_for_layout ?>
This allows them to download a .xsl file by clicking a link that calls
the excel function.
On May 29, 11:15 am, "Howard Glynn" <[EMAIL PROTECTED]> wrote:
> I have successfully used the XML webservice to export my records in
> that form as well as a regular html view just by varying the url
>
> The manual describes webservices as "rss, xml, rest, soap, xmlrpc"
> (Section 4 Advanced routinghttp://manual.cakephp.org/chapter/configuration)
>
> I know CSV is not strictly a webservice, but I would dearly love to add it
> to this list as the consumers on my app expect to be able to paste into
> a spreadsheet, and this would be very convenient in terms of consistency
>
> Can anyone point me in the right direction of how I do this?
>
> I tried following the pattern for xml (items/xml/view.thtml,
> layouts/xml/default.thtml etc)
> but each time I try to go to a URL likehttp://..../csv/items/view/1234
> ... I get an error about a missing CSV controller. I suspect I just need to
> update some file
> or configuration or route to sort this out
>
> Am I missing something obvious?
> Howard
>
> --
> --
> Howard Glynn [ [EMAIL PROTECTED] ]
> Edinburgh, UK
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---