使用POST数据重定向到新页面(PHP/Zend) [英] Redirect to new page w/ POST data (PHP/Zend)
问题描述
我正在尝试找出如何重定向到新页面(不同的应用程序,控制器,操作)并维护当前的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
,是否要使用相同的POST数据将(302)重定向到/app2/example.可能是这样的吗?
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!