Skip to content
Advertisement

How send Id to my view in redictionRoute Symfony

(Sorry for my english)

I’m making a subscribe system (the flush is ok in database) than:

return $this->redirectToRoute('organize_home',);

My Route of redirection needs an Id

/**
 * @Route("/mon-compte/{id}", name="organize_home")
 */
public function accountHomepage(User $user)
{
    return $this->render('user/organize_home.html.twig');
}

How can I send this id to the redirection ?

I tried to play with the user object but no success

Advertisement

Answer

Try this

return $this->redirectToRoute('organize_home', ['id' => "MY_ID"] );

Or (PHP < 5.4)

return $this->redirectToRoute('organize_home', array('id' => "MY_ID") );

Symfony should then load the User with that ID and inject it into accountHomepage(User $user) automatically.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement