Symfony 4 redirectToRoute 不要使用 Post 方法发送参数

Symfony 4 redirectToRoute dont send parameters with Post method

redirectToRoute 方法不将参数发送到其他路由 PS:我使用POST方法

第一条路线:

/**
 * @Route("/CheckAuthentification",name="security_authentification")
 */
public function authentification(Request $request)
{
    *
    *
    *
        return $this->redirectToRoute('profil', ['categories'=>$categories,'user'=>$user]);
   }

第二条路线:

/**
 * @Route("/Profil",name="Profil_page")
 */
public function profil($categories,$user)
{
    return $this->render('user/profil.html.twig',['categories'=>$categories,'user'=>$user]);
}

错误:

Controller "App\Controller\ProfilController::profil()" requires that you provide a value for the "$categories" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

解决方法是在会话中发送对象 第一条路线:

$this->container->get('session')->set('user', $user);
$this->container->get('session')->set('categories', $categories);
return $this->redirectToRoute('profil');

第二条路线:

$user = $this->container->get('session')->get('user');
$categories = $this->container->get('session')->get('categories');
return $this->render('user/profil.html.twig',['categories'=>$categories,'user'=>$user]);