symfony - symfony 5 获取多对多关系的数据
问题描述
我如何获得表的 user_id :user_evento?
我需要比较谁用户加入表: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 %}
解决方案
如果你试图列出Users
与特定对象相关的列表,Evento
你应该在方法返回的集合中找到它们Evento::getUsers()
,前提是你遵循了 Symfony 的最佳实践。
{% for user in eventos.getUsers %}
...
{{ user.nombre }}
...
{% endfor %}
推荐阅读
- html - CSS / Bootstrap - 如果文本超过列长度,则将文本移动到新行
- c - 将 fget 与 realloc() 一起使用
- google-chrome - dlopen 失败:找不到 libmyskia.so 引用的符号“_ZN11SkJpegCodec6IsJpegEPKvj”
- sql - 使用 FROM 子句中的子查询进行联接操作中的 SQL 语法错误
- java - 用数学序列填充数组
- javascript - 如何将视频流发送到 node.js 服务器
- scikit-learn - 限制 scikit k 均值聚类中的质心运动
- angular - Karma 无法运行测试:执行 0 of 0 错误
- mongodb - 更新文档中的多个通用字段
- mysql - 错误:无法删除或更新父行:外键约束失败