knp-snappy-bundle 有私服

knp-snappy-bundle has private service

从 Symfony 2.2 更新到 Symfony 3.4 后出现错误

The "knp_snappy.pdf" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

config.yml

knp_snappy:
  pdf:
    enabled: true
    binary:  '%knp_snappy_pdf_binary%'
    options: []

在控制器操作中:

$html = $this->renderView(
    'FsaBundle:Registration:registrationEmail.html.twig', ['data' => $data]
);

$pdf = $this->get('knp_snappy.pdf')->getOutputFromHtml($html);
...

如何制作knp_snappy.pdfpublic?

KnpSnappyBundle 升级到 1.5.2:他们已经为您完成了。 如果您要重新定义服务(应该没用),请将 public: true 放在定义中。

此外,将 ^1.5 作为 composer.json 中的版本,以便接收此捆绑包的所有兼容升级 (< 2)(我建议每三分之一这样做composer update

期间 semantic versioning) 之后的派对代码

如果您想了解更多关于 composer 及其限制的信息,请查看 ^ (caret) documentation