如何在我的文件树枝类型BLOB Symphony2中显示图片?

时间:2016-02-16 22:59:06

标签: symfony web twig

[实体档案][1]

Controller

thx求助

1 个答案:

答案 0 :(得分:0)

Controller

$images = array();
$em = $this->getDoctrine->getManager();
$probleme = $em->getRepository('PiCrowdRiseWebBundle:Probleme')->findAll();
foreach ($probleme as $key => $entity) {
    $images[$key] = base64_encode(stream_get_contents($entity->getFoto()));
}

// ...

return $this->render('PiCrowdRiseWebBundle:Probleme:problemList.html.twig', array(
    'problemes' => $probleme,
    'images' => $images,
));

查看:

{% for key, entity in problemes %}
   {# ... #}
   <img alt="Embedded Image" src="data:image/png;base64,{{ images[key] }}" />
   {# ... #}
{% endfor %}