symfony 2.8如何获得当前登录用户认证的多个部门列表
我想在登录用户的个人资料页面下显示多个部门及其多个认证的列表 如何在细枝文件中显示列表 清单是这样的symfony 2.8如何获得当前登录用户认证的多个部门列表,symfony,many-to-many,Symfony,Many To Many,我想在登录用户的个人资料页面下显示多个部门及其多个认证的列表 如何在细枝文件中显示列表 清单是这样的 Sector: Agriculture | Accreditations: A1, A2 ,A3 Sector: Cinematography | Accreditations: C1, C2 ,C3 我想从用户_sector表中获取扇区,该表具有 user_id | sector_id 1 | 2 1 | 3 和用户认证表中的认证 user_id | accr
Sector: Agriculture | Accreditations: A1, A2 ,A3
Sector: Cinematography | Accreditations: C1, C2 ,C3
我想从用户_sector表中获取扇区,该表具有
user_id | sector_id
1 | 2
1 | 3
和用户认证表中的认证
user_id | accreditation_id
1 | 1
1 | 2
此外,我在两个实体之间存在多对多关系:用户和部门以及用户和认证
这是我的控制器功能:
public function editAction(Request $request)
{
$user = $this->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$form = $this->createAboutMeForm($user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->get("user_manager")->updateUser($user);
$url = $this->generateUrl('user_dashboard_profile_edit_about_me');
return new RedirectResponse($url);
}
$em=$this->getDoctrine()->getManager();
$user1 = $em->getRepository('UserBundle:User')->findAll();
return $this->container->get('templating')->renderResponse(
'UserBundle:Dashboard/Profile:edit_about_me.html.twig',
array(
'form' => $form->createView(),
'user' => $user,
'userSectors'=>$user->getSectors(),
'userAccreditation'=>$user->getAccreditationdata()
)
);
}
模板文件:
<div class="error-container">{{ form_errors(form.sectors) }}</div>
<span class="label">
{{ form_label(form.sectors) }}
</span>
<div class="field-holder">
{{ form_widget(form.sectors, {
'attr': {
'class': "form-control"
}
}) }}
</div>
</div>
<div class="field-row from">
<div class="error-container">{{ form_errors(form.accreditationdata) }}</div>
<span class="label">
{{ form_label(form.accreditationdata) }}
</span>
<div class="field-holder custom_hide">
{{ form_widget(form.accreditationdata, {
'attr': {
'class': "form-control"
}
}) }}
</div>
</div>
<a href="javascript:void(0)" id="add-sector-accreditation">Add</a>
<ul>
{% for sectors in userSectors %}
<li><span>{{sectors.name}}</span></li>
{% endfor %} |
{% for accre in userAccreditation %} <li>
<span>{{accre.name}}</span></li>
{% endfor %}
</ul>
有人吗?您的数据建模有问题。
由于它向我们公开,您在行业和认证之间没有任何联系,因此您无法将它们汇总。请详细说明您的问题。