我有一个链接:
    {% for item in list %}
        ...
        <a href="{{ path('show', { 'id': item.id }) }}"> read pdf file</a>
    {% endfor %}
当用户单击链接时,我想显示 pdf 文件(在 mysql 中存储为 blob 的文件)。下面的代码不正确,但我希望我的操作执行如下操作。
    /**
    * @Route("/show", name="show")
    */
    public function showAction()
    {
        $id = $this->get('request')->query->get('id');
        $item = $this->getDoctrine()->getRepository('MyDocsBundle:Files')->file($id);
        $pdfFile = $item->getFile(); //returns pdf file stored as mysql blob
        $response = new Response();
        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'application/pdf');
        $response->setContent($pdfFile);
        $response->send() //not sure if this is needed
        return $response;
    }