开发者

Zend Framework And Parameters

Is there any way how to view all sent parameters if I do not know their name?

For example, I sent these parameters:

  • id = 1 (GET)
  • name = 'John' (GET)
  • surname = 'Smith' (GET)

Example

$request = $this->getRequest();
echo $request-&g开发者_如何学运维t;getParam[0]; // Will output 1
echo $request->getParam[1]; // Will output 'John'
echo $request->getParam[2]; // Will output 'Smith'

Thank you!

(I'm not a native English speaker.)


You can use the getParams() method to get a combination of all the request params:

$params = $this->getRequest()->getParams();

foreach($params as $key => $value) {
    // Do whatever you want.
}

There are also getQuery() and getPost() methods.


$request = $this->getRequest();
print_r($request->getQuery()); // returns the entire $_GET array
print_r($request->getQuery("foo")); // retrieve a single member of the $_GET array

So to grab the parameter names and values programmatically, for example, in a simple loop:

foreach($request->getQuery() as $key => $value) {
    echo "Key is: " . $key . " and value is: " . $value . '<br />';
}

Check out the API docs for Zend_Controller_Request_Http.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜