Symfony 2 redirect using POST

后端 未结 3 1419
陌清茗
陌清茗 2021-01-04 05:16

In Symfony 2 I have the following code in my Controller:

// prepare to render the seller info panel
$response = array(
    \'data\' => $data,
);

// rende         


        
相关标签:
3条回答
  • 2021-01-04 05:39

    Latest way of doing POST request redirect (as of Symfony 2.6) is simply:

    return $this->redirectToRoute('route', [
        'request' => $request
    ], 307);
    

    Code 307 preserves the request method, while redirectToRoute() is a shortcut method.

    0 讨论(0)
  • 2021-01-04 05:40

    I had the same error with you when I used $this->generateUrl with passed parameters. However, my redirect worked when I tried this:

    $this->get('router')->generate('route_name', array('param1' => 'paramVal'))
    

    (I know it would not help you that much right now.)

    0 讨论(0)
  • 2021-01-04 05:53

    It's impossible to redirect a POST request because the browser would have to re-send the POST data (which it doesn't). What you should do instead in this case is use forwarding.

    0 讨论(0)
提交回复
热议问题