I'm trying to create an excel file with the jquery library jquery file download. This is what I have now:
var data = {{ tableresults|json_encode|raw }};
$('#exporttocsv').click(function(){
$.fileDownload('dashboard/exporttocsv/' + data, {
successCallback: function (url) {
alert('You just got a file download dialog or ribbon for this URL :' + url);
},
failCallback: function (html, url) {
alert('Your file download just failed for this URL:' + url + '
' +
'Here was the resulting error HTML:
' + html
);
}
});
});
In my function I have this:
public function exporttocsvAction(Application $app, Request $request)
{
$data = $request->request->get('data');
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=test.csv");
header("Pragma: no-cache");
header("Expires: 0");
$output = fopen("php://output", "w");
foreach ($data as $row)
{
fputcsv($output, $row, ',');
}
fclose($output);
exit();
}
But when I dump my $data variable in my function I just get a string like this:
string(271) "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
How can I make sure that I get an array in my php function? I've also tried {{ tableresults }} without json_encode and raw but that gave a syntax error:
var data = <br />
UPDATE:
this a dump of the array I send to my view: http://pastebin.com/Y58aLqBX