【发布时间】:2025-04-17 08:15:02
【问题描述】:
所以我有一个应用程序,我想为几个用户显示一个计划。在我显示计划之前,用户可以在表单中选择一天。 对于周一 = 1 和周五 = 5 的工作日。我将其存储在我的数据库中,用户有一个计划日。 所以在我的控制器中,我这样做是为了检索所有共享相同计划的用户
$planningRepo = $this->getDoctrine()->getManager()->getRepository('OCPediBundle:Planning');
$user = $this->getUser();
$planningID = $user->getPlanning()->getId();
$planning = $planningRepo->find($planningID);
$userRepo = $this->getDoctrine()->getManager()->getRepository('OCUserBundle:User');
$users = $userRepo->findByPlanning($planningID);
var_dump($users);
if (null === $planning) {
throw new NotFoundHttpException("Le planning d'id ". $id. " n'existe pas.");
}
return $this->render('::planning.html.twig', array('planning' => $planning,
'users' => $users));
}
在我的树枝视图中:
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Lundi</th>
<th>Mardi</th>
<th>Mercredi</th>
<th>Jeudi</th>
<th>Vendredi</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Responsable</th>
{% for user in users %}
{{dump(user.planningday)}}
{% if user.planningday == 1 %}
<td>{{user.name}} {{user.lastname}}</td>
{% elseif user.planningday == 2 %}
<td>{{user.name}} {{user.lastname}}</td>
{% elseif user.planningday == 3 %}
<td>{{user.name}} {{user.lastname}}</td>
{% elseif user.planningday == 4 %}
<td>{{user.name}} {{user.lastname}}</td>
{% else %}
<td>{{user.name}} {{user.lastname}}</td>
{% endif %}
{% endfor %}
</tr>
<tr>
<th scope="row">Description</th>
{% for user in users %}
{% if user.planningday == 1%}
<td>{{user.planningcontent}}</td>
{% elseif user.planningday == 2 %}
<td>{{user.planningcontent}}}</td>
{% elseif user.planningday == 3 %}
<td>{{user.planningcontent}}}</td>
{% elseif user.planningday == 4 %}
<td>{{user.planningcontent}}}</td>
{% else %}
<td>{{user.planningcontent}}}</td>
{% endif %}
{% endfor %}
</tr>
</tbody>
</table>
</div>
但是我的问题是,我的 if 语句不起作用。示例我有一个用户选择第 2 天,所以星期二,名字、姓氏和内容显示在星期一 td 中。 任何人都可以帮助我吗?谢谢
【问题讨论】: