views:

52

answers:

2

Hi!

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

+1  A: 
$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.

karim79
+2  A: 

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.

smack0007
exactly what's on my mind but more clearer. Mine was var_dump($this->getRequest()->getParams();)
Hanseh
@Hanseh - if the OP wants to print out the keys and values of `$_GET` parameters the ZF way, using `$request->getParams()` will also give him the controller, action and module in addition (which he may not want, judging from the specificity of the question).
karim79
@karim79 - my mistake. I was just reiterating the idea that getParams() function is available and he can get his needed variable by manipulating it. Thanks for the correction.
Hanseh