我有一个中间表单处理器,它需要从表单中获取POST数据并对其进行操作,然后使用Zend_Controller_Request_Http将其放回post超级全局中。另外,我需要使用POST将新的请求方法设置为Zend_Controller_Request_Http类型。
使用$request->setParam(),是将其添加到post数据中,还是只添加参数的散列?
因此,总括而言:
- Set the Zend_Controller_Request_Http request object method as type POST
- Set the modified POST data to the new POST request data (I imagine its setting it into the superglobals but i want to use Zend Request Object instead).谢谢。
发布于 2015-07-29 20:37:48
嗯,不知道你在尝试什么,但让我给你一些建议。
Zend Request对象正是这个对象,它包含与请求有关的所有内容。更确切地说,原始请求,在这方面,不应该更改请求中的元素。在许多方面,它只是从公共源获取值,并通过这个公共接口提供这些值。例如,方法getParams()返回它在$_GET或$_POST中找到的值,也就是说,如果您的数据是通过GET或POST方法提交的,您就不必担心。
尽管如此,您不能通过Zend对象更改超级全局,因为您永远不应该这样做。但是,您可以直接更改它们,然后请求对象将反映任何更改,因为它们不是永久存储的。
下面是在控制器操作中可以(但不应该)做的事情的示例:
$params = $this->getRequest()->getParams();
$isPost = $this->getRequest()->isPost();
var_dump(compact('isPost','params'));
$_GET['something'] = 'new';
$_SERVER['REQUEST_METHOD'] = 'POST';
$params = $this->getRequest()->getParams();
$isPost = $this->getRequest()->isPost();
var_dump(compact('isPost','params'));
// here is result 1
array (size=2)
'isPost' => boolean false
'params' =>
array (size=3)
'controller' => string 'index' (length=5)
'action' => string 'index' (length=5)
'module' => string 'default' (length=7)
// here is result 2
array (size=2)
'isPost' => boolean true
'params' =>
array (size=4)
'controller' => string 'index' (length=5)
'action' => string 'index' (length=5)
'module' => string 'default' (length=7)
'something' => string 'new' (length=3)https://stackoverflow.com/questions/31703400
复制相似问题