I have a project where people can book places on events. There are dozens of events. I have been requested to generate a report listing attendees so they can be checked in at the door. Because there are so many events, I would like to add an "Attendees Report" button to the editform for each event. I have the button, and it works.
BUT... instead of outputting the data in a CSV, I get the (correct) data displaying in the CMS as if it was being echoed.
Here is my function
//***********************************************
public function getCustomersForEvent($data, $form){
//***********************************************
$attendees = CustomerOrderLine::get()->filter(array("EventID" => $data["ID"]));
if(!$attendees){
return false;
}
$fileName = "report.csv";
$separator = ",";
$csvColumns = array("ID", "Description", "Customer");
$fileData = "";
foreach($attendees as $row){
$fileData .= $row->Event()->EventName . $separator;
$fileData .= $row->CustomerOrder()->Customer()->FirstName . " " . $row->CustomerOrder()->Customer()->Surname . "\n";
}
return SS_HTTPRequest::send_file($fileData, $fileName, 'text/csv');
}
I have had a look at this http://www.silverstripe.org/community/forums/general-questions/show/15325 but the data echoed to the CMS anyway.
Can someone please tell me what I am doing wrong? As I said, the data is fine, but I'm not getting the CSV Open or Save dialog.