【发布时间】:2017-10-22 13:14:25
【问题描述】:
我想在我的文件 twig 中显示来自 bdd 的图像的 url 我收到如下图像错误:
这是我的 bdd :
和我从树枝上的观点:
{% extends '@App/layout.html.twig' %}
{% block title %} Illustration {% endblock %}
{% block body %}
<div class="col-md-4 col-md-offset-4 text-center">
<h2> {{ imageFormation.image.nom }}</h2>
<hr>
<img src=" {{ imageFormation.image.url |raw }} "/><br><br>
</div>
{% endblock %}
你能帮我解决我的问题吗? 我不知道为什么我不能得到真实的图像。
编辑:
/**
* @Route("/formation/{formation}" , name="image")
* @param $image
* @return \Symfony\Component\HttpFoundation\Response
*/
public function imageFormationAction($formation){
$doctrine = $this->container->get('doctrine');
$em = $doctrine->getManager();
$imageRepository = $em->getRepository('AppBundle:Formation');
$imageFormation = $imageRepository->findOneByid($formation);
return $this->render('@App/formation/formationImage.html.twig', array(
'imageFormation' => $imageFormation
));
}
【问题讨论】:
-
为什么你的图片需要绝对路径?使用相对路径可以轻松完成这项工作。只需将图片放在
web/directory1中,然后使用<img src="{{ asset('directory1/' ~ imageFormation.image.url }}">。
标签: php database image symfony