php - Symfony 和 Phantom JS 包 - 路由错误

标签 php html symfony phantomjs rasterize

我正在使用 this将 HTML 转换为 PDF 文件的 bundle 。

实际转换有效,但我在理解路由时遇到问题。

这是我的代码:

/**
 * @Route("/formulare/selbstauskunft/{keycode}", name="saPrint")
 */
public function saPrintAction(Request $request, $keycode)
{


    $em = $this->getDoctrine()->getManager();
    $sa = $em->getRepository('AppBundle:Selfinfo')->findOneBy(array(
        'keycode' => $keycode,
    ));

    if(count($sa) > 0){

        $response = new Response(
            $this->get('padam87_rasterize.rasterizer')->rasterize(
                $this->renderView('default/formSAPrint.html.twig', array(
                    'selfinfo' => $sa,
                ))
            ),
            200, [
                'Content-Type'          => 'application/pdf',
                'Content-Disposition'   => 'attachment; filename="my.pdf"'
            ]
        );

        return $response;

    }else{
        return new Response("fail");
    }
}

该包创建了 2 个文件,rasterize-UNIQUEID.htmlrasterize-UNIQUEID.pdf。 html 文件包含正确的输出。 在 /bundles/padam87rasterize/temp/ 中创建 html 文件后,脚本的第二部分通过 url 调用打开此文件 here . 不幸的是,实际呈现的页面是一个 symfony 错误页面,上面写着:

No route found for GET /bundles/padam87rasterize/temp/rasterize-UNIQUEID.html

我必须设置什么才能呈现 html 文件?

最佳答案

我认为您实际上必须创建一个单独的路由来呈现 html。据我所知,rasterize 函数从临时 html 文件生成 pdf(关键字是临时的)。

关于php - Symfony 和 Phantom JS 包 - 路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34130093/

相关文章:

php - 如何制作 slider div?

html - 弹出窗口没有出现在正确的位置

javascript - 在迭代期间在每个容器中复制图像

html - 自定义 Bootstrap 的链接仅在悬停时显示为按钮

html - twig 定义了如何在 View 中呈现

ajax - $ request-> isXmlHttpRequest()在symfony2中可靠吗?

php - Doctrine - 查询相关实体的条件

php - (php) 日期和时间

php - 无法使 PHP 更新功能正常工作

javascript - 提交一个通过ajax调用的表单