我如何在Zend框架MVC中检索HTTP请求数据


How can I retrieve HTTP Request data in Zend Framework MVC?

我知道,有很多方法。我希望你能给我很多方法让我选择。

我真的不确定你之后,但从一个控制器上下,有几个方法来访问请求参数(注意,这是不一样的$_REQUEST)。

$param = $this->getRequest()->getParam('param');
$param = $this->getRequest()->param; // provided the param name satisfies PHP object property rules for use in __get()
$param = $this->_getParam('param-name'); // same as above

源自Zend_Controller_Request_Http::__get()

作为public成员访问超全局变量中包含的值
优先顺序:1。, 2。帖子,3。饼干4。服务器,5。ENV

注释没有提到的是,它首先检查内部的"实例"参数数组。

在控制器内部,你应该使用

$all = $this->getRequest()->getParams();
$one = $this->getRequest()->getParam('key');
$all = $this->_request->getParams();
$one = $this->_request->getParam('key');
$all = $this->_getAllParams();
$one = $this->_getParam('key');

或者从控制器外部(在前控制器加载后)

$front = Zend_Controller_Front::getInstance();
$all = $front->getRequest()->getParams();
$one = $front->getRequest()->getParam('key');