问题描述
我想弄清楚如何重定向到新页面(不同的应用程序、控制器、操作)并维护当前的 POST 数据.
I'm trying to figure out how to redirect to a new page (different application, controller, action) and maintain the current POST data.
我的应用程序正在验证 POST 数据,如果满足特定条件,我想重定向到其他位置,但请确保将 POST 数据作为 POST 数据传递到该新页面.这是一个粗略的例子:
My app is validating the POST data and if a certain criteria is met, I want to redirect to a different location, but make sure the POST data is passed as POST data to that new page. Here's a rough example:
POST /app1/example HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 17
var1=foo&var2=bar
在我的 exampleAction
(Zend_Controller_Action) 中,我检查是否 var1 == foo
,如果是,我想将 (302) 重定向到/app2/example使用相同的 POST 数据.可能是这样的吗?
In my exampleAction
(Zend_Controller_Action), I check to see if var1 == foo
, and if it does I want to redirect (302) to /app2/example with that same POST data. Something maybe like this?
HTTP/1.x 302 Found
Location: /app2/example
Content-Type: application/x-www-form-urlencoded
Content-Length: 17
var1=foo&var2=bar
我可以看到如何使用 Zend_Http_Client 创建一个新的 HTTP 请求,但我不想简单地请求页面并显示内容.无论如何我仍然应该使用 Zend_Http_Client 吗?目前我正在玩这样的东西:
I can see how to create a new HTTP request using Zend_Http_Client, but I'm not looking to simply request the page and display the content. Should I still be looking to use Zend_Http_Client anyway? At the moment I'm playing with stuff like this:
$this->getResponse()->setRedirect('/app2/example/', 302);
$this->getResponse()->setBody(http_build_query($this->_request->getPost()));
我确信我想做的事情可以通过某种诡计和恶魔般的手段来实现,但这绝对是在暗指我.任何帮助表示赞赏.
I'm sure what I want to do is possible through some means of trickery and demon-cavorting, but it's definitely alluding me. Any help is appreciated.
- rk
推荐答案
与其将浏览器重定向到新位置,为什么不直接将请求从控制器转发到另一个控制器?
Rather than redirecting the browser to the new location, why not just forward the request from the controller to the other controller?
return $this->_forward("action", "controller", "module");
这篇关于重定向到带有 POST 数据的新页面(PHP/Zend)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!