使用twig(symfony2)无法在视图中显示上传的图像

时间:2014-12-22 10:28:35

标签: twig

我在一个使用symfony的项目中工作,我有一个视图,我在其中显示一个实体的图像,我使用与文档推荐的相同的上传方法,上传是工作正常,但是当我想要显示图像时遇到的问题,我得到如下例外:

A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "." ("punctuation" expected with value ":") in StockStockBundle:Payantfournisseur:imprime.html.twig at line 135

有代码给我这个例外: 在控制器方面:

$em = $this->getDoctrine()->getManager();

    $entity = new Payantfournisseur();
    $entity = $em->getRepository('StockStockBundle:Payantfournisseur')->find($id);
    $user = $this->get('security.context')->getToken()->getUser();
    $societe = new \User\UserBundle\Entity\Societe();
    $societe = $em->getRepository('UserUserBundle:Societe')->find(2);
    //$societe = $user->getSociete();
    $facture = $entity->getIdfacturefournisseur();
    $fournisseur = $facture->getIdfournisseur();
    $articles = $em->getRepository('StockStockBundle:Lignefacturefournisseur')
                       ->getArtFromLines($facture);


    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Devis entity.');
    }

    $deleteForm = $this->createDeleteForm($id);

    return $this->render('StockStockBundle:Payantfournisseur:imprime.html.twig', array(
        'entity' => $entity,
        'fournisseur' => $fournisseur,
        'facture' => $facture,
        'articles' => $articles,
        'delete_form' => $deleteForm->createView(),
        'societe' => $societe,


            // 'ayoub'=>'yes ayoub',
    ));

在视图方面:

<img src="{{ asset({societe.pjs.getWebPath}) }}" alt="{{ societe.pjs.alt }}" class="spaced img-responsive" /> 

给予更多解释,pjs是与societe相关的oneToOne实体,pjs是负责上传文件的实体。

如果有人有想法,那么它可能会非常有用 提前致谢!!!!!!!

1 个答案:

答案 0 :(得分:1)

我在树枝中发现了解析错误

从资产功能中删除大括号,使用如下变量:

<img src="{{ asset(societe.pjs.getWebPath) }}" alt="{{ societe.pjs.alt }}" class="spaced img-responsive" />