简体   繁体   English

Symfony-TCPdf-无法找到模板

[英]Symfony - TCPdf - Unable to find template

I'm stuck with an annoying error with TCPdf and Symfony: 我陷入与TCPdf和Symfony一个烦人的错误:

request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Unable to find template "" (looked into: /Applications/MAMP/htdocs/api/app/Resources/views)." at /Applications/MAMP/htdocs/api/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 {"exception":"[object] (InvalidArgumentException(code: 0): Unable to find template \\"\\" (looked into: /Applications/MAMP/htdocs/api/app/Resources/views). at /Applications/MAMP/htdocs/api/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php:128, Twig_Error_Loader(code: 0): Unable to find template \\"\\" (looked into: /Applications/MAMP/htdocs/api/app/Resources/views). at /Applications/MAMP/htdocs/api/vendor/twig/twig/lib/Twig/Loader/Filesystem.php:215)"} []

In my controller I just create a pdf and output it: 在我的控制器中,我只是创建一个pdf并输出:

public function pdfAction()
{
    $pdf = ...;
    ...
    $pdf->output();
}

My best guess is that Symfony is trying to return a Response (but the output already gave one) and thus the error. 我最好的猜测是Symfony试图返回一个Response(但是输出已经给出了一个),因此出现了错误。 However I cannot find how I should resolve this in Symfony. 但是我找不到如何在Symfony中解决此问题的方法。 Any help or tips are welcome. 欢迎任何帮助或提示。

PS: The pdf works perfectly, only monologger that is spamming me with errors .. PS:pdf可以完美运行,只有monologger会向我发送错误消息..

For future reference : 供将来参考

This is how I solved it in the end: 这是我最终解决的方式:

$pdf->Output('output.pdf', 'I');
return new Response();

I tried many different options but this is the only one that doesn't trigger that error. 我尝试了许多不同的选项,但这是唯一不会触发该错误的选项。

With Symfony you need to return response as array. 使用Symfony,您需要将响应作为数组返回。

Maybe this piece of code works: 也许这段代码可以工作:

$pdfOutput = $pdf->output();

return array('pdfOutput' => $pdfOutput); // or just try to return $pdf;

// If you don't use annotation : 
return $this->render('your-template.html.twig', array(
    'pdfOutput' => $pdfOutput
));

And in your template, if you want to result some things, your template looks like that : 在模板中,如果要生成一些结果,则模板如下所示:

{{ dump(pdfOutput) }}

EDIT 编辑

Try with a path as arguments 尝试使用路径作为参数

$pdf->Output("output.pdf", 'I'); $ pdf-> Output(“ output.pdf”,'I');

TCPDF output doc TCPDF输出文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM