Created
February 27, 2019 15:56
-
-
Save beamop/1715c769f8b341f93007af734e12419f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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