Skip to content

Instantly share code, notes, and snippets.

@beamop
Created February 27, 2019 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beamop/1715c769f8b341f93007af734e12419f to your computer and use it in GitHub Desktop.
Save beamop/1715c769f8b341f93007af734e12419f to your computer and use it in GitHub Desktop.
/**
* @Route("/app/links/export.csv", name="app_export_links")
*/
public function exportLinksAction()
{
$em = $this->getDoctrine()->getManager();
$links = $em
->getRepository(Links::class)
->findAll();
$rows = [];
foreach ($links as $link) {
$data = [$link->getId(), $link->getLink()];
$rows[] = implode(',', $data);
}
$content = implode("\n", $rows);
$response = new Response($content);
$response->headers->set('Content-Type', 'text/csv');
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment