i'm trying to export a twig view into csv, but i'm stuck, can someone help me out with detailled solution ? peace
/**
*
* @Route("/export", name="export_csv")
*/
public function exportAction() {
$entity = new Invite();
$form = $this->createForm(new ManifSearchType(), $entity);
$request = $this->get('request');
$em = $this->getDoctrine()->getManager();
$view = $this->render('PrifProtocoleBundle:Invite:index.html.twig', array(
'form' => $form->createView()));
$handle = fopen('php://memory', 'r+');
$header = array();
fputcsv($handle, $view);
rewind($handle);
$content = stream_get_contents($handle);
fclose($handle);
return new Response($content, 200, array(
'Content-Type' => 'application/force-download',
'Content-Disposition' => 'attachment; filename="export.csv"'
));
}
error message:
Warning: fputcsv() expects parameter 2 to be array, object given in C:\wamp\www\protocole\src\Prif\ProtocoleBundle\Controller\InviteController.php line 56
index.html.twigactually html formatted? If it is csv formatted, there is a better way to output a csv file.