Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2如何将DataSase数据导出到csv_Php_Symfony_Csv_Doctrine - Fatal编程技术网

Php Symfony2如何将DataSase数据导出到csv

Php Symfony2如何将DataSase数据导出到csv,php,symfony,csv,doctrine,Php,Symfony,Csv,Doctrine,我想将数据库数据导出到CSV,并在单击按钮后下载CSV文件 目前在controller中,我正在使用存储库从数据库获取所有必要的数据 $em = $this->getDoctrine()->getManager(); $entities = $em->getRepository('SkerpInventoryBundle:InventoryMaster')->findAllIndex(); $entities将包含所有数据,我想将其导出到CSV 在小

我想将数据库数据导出到CSV,并在单击按钮后下载CSV文件

目前在controller中,我正在使用存储库从数据库获取所有必要的数据

$em       = $this->getDoctrine()->getManager();    
$entities = $em->getRepository('SkerpInventoryBundle:InventoryMaster')->findAllIndex();
$entities将包含所有数据,我想将其导出到CSV

在小枝中,我有一个用于下载CSV文件的按钮

下面是细枝中按钮的代码-

<a href="{{ path('location') }}">Export as Excel</a>
有什么问题吗

出口代码:

 use Symfony\Component\HttpFoundation\Response;
在控制器中:

    $data = array(1,2,3,4);
    $response = new Response($data);
    $response->headers->set('Content-Type', 'application/octet-stream');
    $response->headers->set('Content-Disposition', 'attachment; filename=filename.csv');
    return $response;