Skip to content

Instantly share code, notes, and snippets.

@whitewhidow
Created October 17, 2017 11:24
Show Gist options
  • Save whitewhidow/34cafa9244e5a5590c3fd6f90854a75f to your computer and use it in GitHub Desktop.
Save whitewhidow/34cafa9244e5a5590c3fd6f90854a75f to your computer and use it in GitHub Desktop.
public function exportCsvAction()
{
$data = [];
$filename = "export_filename_" . date("Y_m_d_His") . ".csv";
$response = $this->render('BBITAdminBundle:Csv:entity.csv.twig', array('data' => $data));
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Description', 'Filename description');
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
$response->headers->set('Content-Transfer-Encoding', 'binary');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Expires', '0');
$response->sendHeaders();
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment