Skip to content

Latest commit

 

History

History
executable file
·
48 lines (34 loc) · 971 Bytes

00-csv-export.md

File metadata and controls

executable file
·
48 lines (34 loc) · 971 Bytes

CsvExport

Basic usage

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.

Callback

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(),
	);
});

CSV controls

You can customize the delimiter and enclosure controls when exporting a CSV:

return $this->CsvExport('foo.csv', $header, $entries, null, ',', '"');