Get values from $request

Asked

Viewed 624 times

0

I would like to take all the values of a certain key of a request.

Ex Request:

nnmSoftware=7-Zip&idSoftware=1181&nmLocal=Empresa&idRede=1&nmSoftware=account-plugin-aim&idSoftware=1&nmLocal=Empresa&idRede=1, referer: http://localhost/app_dev.php/report/software/inventoried

But when I try to take it $software = $request->get('idSoftware'); returns only idSoftware = 1.

How would I get them all? idSoftware = 1, 1181

  • Who $request is that it? Wouldn’t it be $_REQUEST['key']?

  • exactly, gmsantos. But even using $_REQUEST['idSoftware'] it brings only 1 idSoftware

  • I can’t test at the moment, but I believe I can add it to an array: array_push($array, $request->get('idSoftware'))

  • Are you using some framework?

  • Try $var = $_SERVER['QUERY_STRING'];

parse_str($var, $result); print_r($result);

  • @Luishenrique using push array_returns empty.

  • @Wallacemaxters, I use symfony.

  • @Brunomenezes notice your query, you call idSoftware twice! So the value is 1: nnmSoftware=7-Zip& idSoftware=1181 &nmLocal=Company&idrede=1&nmSoftware=Account-plugin-Aim& idSoftware=1 &nmLocal=Empresa&idrede=1. Doing this via GET is not possible, only via POST.

  • @gmsantos. I need to take these two values. In some situations I will have 200 Idsoftwares

  • I’m running out of time to answer now, but basically you need the method to be sent via POST and have [] in the name of input: <input name="idSoftware[]">. Thus idSoftware will be an array.

  • I agree with you and suggest the use of POST. However, selecting the array before going through get would not solve the @gmsantos problem?

  • @gmsantos Perfect. Thank you very much, it was just that.

Show 7 more comments

1 answer

3


In the query, the field idSoftware is repeated twice:

nnmSoftware=7-Zip&idSoftware=1181&nmLocal=Company&idrede=1&nmSoftware=Account-plugin-Aim&idSoftware=1&nmLocal=Company&idrede=1

By doing this GET recognizes only the latter idSoftware worthwhile 1.

To receive all occurrences of idSoftware you need the method to be sent via POST and have [] in the name of input. Thus idSoftware will be an array.

<form method="POST">
    <input name="idSoftware[]">
    <input name="idSoftware[]">
    <input name="idSoftware[]">
</form>

Upshot:

array(1) {
  ["idSoftware"]=>
  array(3) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(118)
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.