Call the plugin with the name of the downloadable CSV file, the header, and the records.
// inside a controller action
$response = $this->CsvExport($filename, $header, $records);
return $response;
The plugin will return a response object which you can then return from your controller action.
In case a record is not a simple array, you can provide an optional callback that will transform the given record into a simple array.
$entries = array(
new Entry('Foo', 'Bar'),
new Entry('Michael', 'Bluth'),
);
$header = array(
'First Name',
'Last Name',
);
return $this->CsvExport('foo.csv', $header, $entries, function(Entry $entry)
{
return array(
$entry->getFirstName(),
$entry->getLastName(),
);
});
You can customize the delimiter
and enclosure
controls when exporting a CSV:
return $this->CsvExport('foo.csv', $header, $entries, null, ',', '"');