1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public function exportDetailsAction() {
$fileName = "export_" . date('d-M-Y'). ".csv";
$req = $this
->getDoctrine()
->getManager()
->getRepository('APPExportBundle:Export')
;
$response = new StreamedResponse();
$response->setCallback(function() use ($req) {
$handle = fopen('php://output', 'w+');
fputcsv($handle, ['champ 1', 'champ 2', 'champ 3', 'champ 4', 'champ 5', 'champ 6', 'champ 7', 'champ 8'], ';');
$id = $this->getUser()->getClient()->getId();
$start = new \DateTime($_POST['app_exportbundle_export']['start']);
$end = new \DateTime($_POST['app_exportbundle_export']['end']);
$lists = $req->findByParam($id, $start, $end);
foreach ($lists as $list) {
fputcsv(
$handle,
[$list->getId(), $list->getNom(), $list->getNomProduit(), $list->getOptions(), $list->getMin(), $list->getMax(), $list->getObject(), $list->getPrice()],
';'
);
}
fclose($handle);
}); |
Partager