我正在尝试将树枝视图输出到csv中,但是我被卡住了,有人可以用详细的解决方案帮助我吗?和平
/**
*
* @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"'
));
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
Warning: fputcsv() expects parameter 2 to be array, object given in C:\wamp\www\protocole\src\Prif\ProtocoleBundle\Controller\InviteController.php line 56
Run Code Online (Sandbox Code Playgroud)
问题是,您不是只想将树枝转换为CSV文件.您正在将HTML转换为CSV文件.现在,这似乎是一个奇怪的转换.
你应该做的是让你的树枝生成CSV内容.像这样:
$response = $this->render('PrifProtocoleBundle:Invite:export.csv.twig',array('data' => $data));
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
return $response;
Run Code Online (Sandbox Code Playgroud)
你的树枝应该以CSV格式呈现.
归档时间: |
|
查看次数: |
6358 次 |
最近记录: |