Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Correct way to get multiple values for same parameter name in GET request

Hi,

I am trying to send multiple values for the same parameter name in a GET request like this:

http://localhost/module?p=value1&p=value2

In my controller, I get the parameters with the following code:

$params = $this->request->getQuery();

And I obtain this:

array(2) { ["_url"]=> string(7) "/module" ["p"]=> string(6) "value2" }

So I guess that the getQuery function retrieves only the last value defined in the query.

Is there a simple way to retrieve an array of these values via Phalcon or do I have to change the format of my query and split it?



1.7k
Accepted
answer

I have found the answer to my question.

I modified my GET request like this:

http://localhost/module?p[]=value1&p[]=value2

Now, I get this:

array(2) { ["_url"]=> string(7) "/module" ["p"]=> array(2) { [0]=> string(6) "value1" [1]=> string(6) "value2" } }