在 Symfony 2 中,我的 Controller 中有以下代码:
// prepare to render the seller info panel
$response = array(
'data' => $data,
);
// render the seller info panel
return $this->redirect($this->generateUrl('route', $response));
路线在哪里:
route:
pattern: /listing/complete/{data}
defaults: { _controller: FooBundle:Foo:action }
requirements:
_method: POST
这不起作用,因为重定向正在发出 GET 请求。我也尝试过这种模式,但它与路线不匹配:
route:
pattern: /listing/complete
defaults: { _controller: FooBundle:Foo:action }
requirements:
_method: POST
我发现路由文档没有帮助。有没有办法让重定向发出 POST 请求?路线会是什么样子,我是否需要在 Controller 中执行任何操作才能实现它?
最佳答案
执行 POST 请求重定向的最新方法(从 Symfony 2.6 开始)很简单:
return $this->redirectToRoute('route', [
'request' => $request
], 307);
代码307
保留了请求方法,而redirectToRoute()
是一个快捷方法。
关于php - Symfony 2 使用 POST 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11227975/