/** * Export collection to PHP output stream. * * @param BaseCollection $collection */ public function exportOutput(BaseCollection $collection, $attachmentName = null) { $filename = $attachmentName ?: $this->defaultFilename(); // use "text/csv" according to RFC 4180. header("Content-Type: text/csv; charset=UTF-8"); header("Content-Disposition: attachment; filename={$filename}"); $outputFd = fopen('php://output', 'w'); $exporter = new BaseCSVExporter($outputFd); $exporter->exportCollection($collection, $this->exportFields); }
public function testCollectionExporter() { $author = new Author(); foreach (range(1, 10) as $i) { $ret = $author->create(array('name' => 'Foo-' . $i, 'email' => 'foo@foo' . $i, 'identity' => 'foo' . $i, 'confirmed' => true)); $this->assertTrue($author->confirmed, 'is true'); $this->assertTrue($ret->success); } @mkdir('tests/tmp', 0755, true); $fp = fopen('tests/tmp/authors.csv', 'w'); $exporter = new CSVExporter($fp); $exporter->exportCollection(new AuthorCollection()); fclose($fp); $authors = new AuthorCollection(); $authors->delete(); $fp = fopen('tests/tmp/authors.csv', 'r'); $importer = new CSVImporter(new Author()); $importer->importResource($fp); fclose($fp); }