2

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

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

exactly what's on my mind but more clearer. Mine was var_dump($this->getRequest()->getParams(); )
@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 - 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.
1
$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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.