symfony 3 - 来自数据库的url图像

时间:2017-05-22 19:03:01

标签: php database image symfony

我想在我的文件树枝中显示来自bdd的图像的网址我收到图片的错误,如: bdd

这是我的bdd: 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
        ));
    }

bdd

bdd

2 个答案:

答案 0 :(得分:1)

您的图片网址必须与网络目录相关,例如此C:\xampp\htdocs\Symfony\MonProjetCv\web\fichier\Mention.jpg,而不是文件系统fichier\Mention.jpg中图片的路径。

在数据库中保存图像文件的相对路径(url等于asset),并在twig文件中使用{% 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=" {{ asset(imageFormation.image.url); }} "/><br><br> </div> {% endblock %} 函数:

 var user = Parse.User();
 user.setUsername("admin", null); 
 user.setPassword("password", null);
 user.save();

答案 1 :(得分:0)

你可以试试这个吗?

$('input').on('change', function() {
       alert($('input[name=options]:checked').attr('id')); 
});