Hi
Today I had one of these moments, where I really enjoyed using silverstripe... I used simple php and it seemed to work seemlessly with silverstripe.
I added the following function to a page controller:
function ExportDetails() {
if(Permission::check('ADMIN')) {
$result = mysql_query("SHOW COLUMNS FROM Mytable");
$select = 'SELECT ';
while($row = mysql_fetch_array($result)) {
$out .= $row["Field"].", ";
$select .= $row["Field"].", ";
$rowFieldNames[] = $row["Field"];
}
$out .= "ID\r\n";
$select .= " ID FROM Mytable";
$result = mysql_query($select);
while($dataRow = mysql_fetch_array($result)) {
foreach($rowFieldNames as $key=>$value) {
$out .= ''.str_replace(",", "[comma]", $dataRow[$value]).', ';
}
$out .= $row["ID"]."\r\n";
}
header("Content-Type: application/txt");
HTTPResponse::addHeader("Content-disposition", "RegistrationsOn".date("Y-m-d").".csv");
print $out;
exit;
}
else {
Security::permissionFailure($this, 'You must be logged in.');
}
}
and all I had to do is to add "ExportDetails" after the url and it works (e.g. mypage/ExportDetails gives the csv output. The only line that does not work is HTTPResponse::addHeader("Content-disposition", "RegistrationsOn".date("Y-m-d").".csv"); - it gives ExportDetails as filename. How can I change this.
I also still have to use the dataobject to retrieve the data rather than good old mysql_query (I just love writing my own sql).
Thank you
Nicolaas