symfony 5获取路由id



我有一个事件,id在route:

http://test/event/19

event-users:
path: /event/{id}
controller: AppControllerevent::event-users

和此页面获取在此事件中注册的用户。

我尝试改变用户的角色,与用户的id,但我只有用户id,我如何得到事件id?,我需要得到Id:http://test/event/19,因为当我刷新数据库时,我得到事件id为null

我尝试改变这个事件的角色用户,


<a href="{{ path('event', {'id':user.id}  )  }}">Change Rol <a>  <br> 

eventRole:
path: /event/user/role/{id}/
controller: AppControllerEventoController::eventRole
public function eventRole(Request $request, UserHasEvento $userhasevento, Evento $evento, User $user){
$evento = $this->getDoctrine()->getRepository(Evento::class)->findOneById($evento);
$form = $this->createForm(EventoUsuarioEditarRolFormType::class, $userhasevento );                
$form->handleRequest($request);                
if($form->isSubmitted() && $form->isValid()){
$formulario = $form->get("tipoinvitado")->getData();
$userhasevento->SetTipoinvitado($formulario);
$userhasevento->SetEventoid($evento);
$userhasevento->SetUserid($user->getId());
dump($userhasevento);die;
$em = $this->getDoctrine()->getManager();
$em->persist($userhasevento);
$em->flush();
return $this->redirect($this->generateUrl('evento_detalle', ['id' => $evento->getId()]));
}        
return $this->render('evento/register-evento2.html.twig',[
'edit' => true,
'form' => $form->createView()
]);

}

你需要在你的路由中使用这两个id。

eventRole:
path: /event/{id}/user/role/{userId}/
controller: AppControllerEventoController::eventRole
@Entity("user", expr="repository.find(userId)")
public function eventRole(Request $request, UserHasEvento $userhasevento, Evento $evento, User $user){
// ...
}
<a href="{{ path('eventRole', {'userId':user.id, 'id': evento.id}  )  }}">Change Rol <a>  <br>

https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html fetch-via-an-expression

相关内容

  • 没有找到相关文章

最新更新