Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created March 30, 2015 14:42
Show Gist options
  • Select an option

  • Save lorenzo/9137457b7f7281ae4ebe to your computer and use it in GitHub Desktop.

Select an option

Save lorenzo/9137457b7f7281ae4ebe to your computer and use it in GitHub Desktop.
<?php
$data = $this->Table->find()->all();
$file = new \SplFileObject(TMP . "my_export.csv", 'w');
$title = function ($row) use ($file) {
static $done = false;
if (!$done) {
$file->fputcsv(array_keys($row));
$done = true;
}
return $row;
};
$data
->map($title)
->each(function ($row) use ($file) {
$file->fputcsv($row);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment