Php Symfony2如何将DataSase数据导出到csv
我想将数据库数据导出到CSV,并在单击按钮后下载CSV文件 目前在controller中,我正在使用存储库从数据库获取所有必要的数据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 在小
$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;