我试图将当前的html页面下载为symfony中的文件:
我的枝条:
<a href="{{ path('polytech_skills_evaluations_export', {'idssoccasion': ssoccasion.id, 'idevalue':user.id}) }}" >Exporter </a>
我的控制器
$html= $this->renderView('PolytechSkillsBundle:Evaluation/Evaluation:type2.html.twig', array(
'form' => $form->createView(),
'niveaux' => $niveaux,
'date' => $dateCourante,
'evalue' => $evalue,
'ssoccasion' => $ssoccasion,
'lasteval' => $lastEval,
'lastevalforocc' => $lastEvalForOccasion,
'objectifs' => $objectifs
));
$response = new Response();
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', mime_content_type($html));
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($html) . '";');
$response->headers->set('Content-length', filesize($html));
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent(file_get_contents($html));
我得到的错误:
Warning: mime_content_type failed to open stream: Invalid argument
500内部服务器错误 - ContextErrorException
答案 0 :(得分:0)
在这种情况下,最好的解决方案是保存(甚至暂时保存页面),然后强行下载:
C
然后,您可以使用以下代码下载文件:
file_put_contents('page.html', $content);
Polytech学校:)?
感谢您的反馈