如何将请求方法设置为 post 并将变量添加到 zend 请求对象中的 post 数组

how to set the request method as post and add variables to post array in zend request object

我有一个中间表单处理器,它需要从表单中获取 POST 数据并对其进行操作,然后使用 Zend_Controller_Request_Http 将其放回 post 超全局。另外,我需要使用 Zend_Controller_Request_Http

将新的请求方法设置为类型 POST

使用 $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).

谢谢。

嗯,不确定你在尝试什么,但让我给你一些建议。

Zend Request 对象就是这样,一个包含 Request 的所有内容的对象。更准确地说,原始请求,在这方面,不应更改请求中的元素。在许多方面,它只是从公共来源获取价值,并通过这个公共接口使它们可用。例如,方法 getParams() returns 在 $_GET$_POST 中找到的值,也就是说,如果您的数据是通过 [=14] 提交的,您将永远不必担心=] 或 POST 方法。

也就是说,您不能通过 Zend Request 对象更改超全局变量,因为您永远不应该那样做。但是,您可以直接更改它们,然后 Request 对象将反映任何更改,因为它们不是永久存储的。

这是您可以(但不应该)在控制器操作中执行的操作的示例:

$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)