Symfony 2使用POST重定向 [英] Symfony 2 redirect using POST

查看:119
本文介绍了Symfony 2使用POST重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Symfony 2中,我的控制器中包含以下代码:

In Symfony 2 I have the following code in my 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请求.我也尝试过这种模式,但是它与路由不匹配:

This doesn't work since the redirect is making a GET request. I've also tried it this pattern, but its not matching the route:

route:
    pattern:  /listing/complete
    defaults: { _controller: FooBundle:Foo:action }
    requirements:
        _method:  POST

我发现路由文档无济于事.有没有一种方法可以使重定向发出POST请求?路线会是什么样子,我是否必须在控制器中做任何事情才能使其实现?

I've found the routing documentation unhelpful. Is there a way that I can have the redirect make a POST request? What would the route look like, and do I have to do anything in the controller to make it happen?

推荐答案

无法重定向POST请求,因为浏览器将不得不重新发送POST数据(不是这样).在这种情况下,您应该使用转发.

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.

这篇关于Symfony 2使用POST重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆