Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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
Symfony 您请求了一项不存在的服务“;knp_snappy.pdf“;_Symfony_Pdf_Pdf Generation_Sonata - Fatal编程技术网

Symfony 您请求了一项不存在的服务“;knp_snappy.pdf“;

Symfony 您请求了一项不存在的服务“;knp_snappy.pdf“;,symfony,pdf,pdf-generation,sonata,Symfony,Pdf,Pdf Generation,Sonata,我继续学习教程 app/config/config.yml knp_snappy:`enter code here` pdf: enabled: true binary: /usr/local/bin/wkhtmltopdf options: [] image: enabled: true binary: /usr/local/bin/wkhtmltoimage options: [] app/AppKernel new Knp\Bundle\S

我继续学习教程

app/config/config.yml

knp_snappy:`enter code here`
pdf:
    enabled: true
    binary: /usr/local/bin/wkhtmltopdf
    options: []
image:
    enabled: true
    binary: /usr/local/bin/wkhtmltoimage
    options: []
app/AppKernel

new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
霉菌控制者

use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;

public function pdfAction(string $offerId)
{
    $html = $this->renderView('@App/Offer/offer_pdf.html.twig', array(
        'offerId'  => $offerId
    ));

    return new PdfResponse(
        $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
        'file.pdf'
    );
}
我试着这样做:

 public function offerToPDFAction(string $offerId)
{

    $snappy = $this->container->get('knp_snappy.pdf');

    $html = '<h1>Hello</h1>';

    $filename = 'myFirstSnappyPDF';

    return new Response(
        $snappy->getOutputFromHtml($html),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="'.$filename.'.pdf"'
        )
    );
公共函数offerUpdate(字符串$offerId)
{
$snappy=$this->container->get('knp_snappy.pdf');
$html='Hello';
$filename='myFirstSnappyPDF';
返回新的响应(
$snappy->getOutputFromHtml($html),
200,
排列(
“内容类型”=>“应用程序/pdf”,
“内容处置”=>“附件;文件名=“”.$filename..pdf””
)
);
同样的问题:
您请求了一个不存在的服务“knp\u snappy.pdf”.

config.yml中的缩进只是一个复制/粘贴问题?php bin/console debug:container是否显示knp_snappy.pdf服务?您是否清除了缓存?我认为这会使您的.yml无效=>
在此处输入代码
,请尝试删除使用php bin/console debug:container选中的itI,它会出现,我会清除缓存,但没有任何结果。“在这里输入代码”-它出现在stackoverflow中,我没有奇怪的代码。只是为了确保,您的控制器像“class DefaultController extends controller”一样扩展symfony FrameworkBundle控制器?您可以加载任何其他服务,如logger或mailer吗?
use Knp\Snappy\Pdf;

use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;

/**
 * @Route("/show/pdf/{token}", name="admin_invoice_show_pdf", methods={"GET"})
 */

public function showPdf(Command $command, Pdf $pdf)
{

  $html = $this->renderView('admin/invoice/showPdf.html.twig',array('command' $command));
  return new PdfResponse($pdf->getOutputFromHtml($html), 'invoice.pdf');

}