symfony 5 获取多对多关系的数据 [英] symfony 5 get data of many to many relation

查看:30
本文介绍了symfony 5 获取多对多关系的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得表的 user_id :user_evento ?

how i get user_id of table : user_evento ?

我需要比较谁加入了表:evento

i need compare who user join on table : evento,

在此处输入图片描述

控制器

    public function evento_detalle(Evento $evento){
        if(!$evento){
          return $this->redirectToRout('ver_eventos');
        } 
        $salas = $this->getDoctrine()->getRepository(Sala::class)->findBy([],['id' => 'desc']);
        $users =  $this->getDoctrine()->getRepository(User::class) ->findBy([],['id' => 'ASC']);

        return $this->render('evento/ver-evento.html.twig',[
            'eventos' =>$evento,
            'users' =>$users,
            'salas' =>$salas
        ]);

    }

树枝

{% for user in users %}
    {% if user.id == eventos.getUsers.evento %}
    <tr>
        <td>

        {{ user.nombre }} 

        </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td>  </td>

    </tr>
    {%endif%}
{% endfor %}    

推荐答案

如果您尝试列出与特定 Evento 关联的 Users,您应该在Evento::getUsers() 方法返回的集合,前提是您遵循了 Symfony 的最佳实践.

If you are trying to list Users associated with a particular Evento you should find them all in the collection returned by the Evento::getUsers() method, provided you have followed best practices for Symfony.

{% for user in eventos.getUsers %}
  ...
  {{ user.nombre }} 
  ...
{% endfor %}    

这篇关于symfony 5 获取多对多关系的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆