# How to get 3 parameters from the url with slim 4

**URL:** <https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767>\
**Category:** Questions\
**Created:** [December 5, 2023, 9:58pm UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767 "2023-12-05T21:58:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlramirez](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jlramirez](https://discourse.slimframework.com/u/jlramirez)\
**Post date:** [December 5, 2023, 9:58pm UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/1 "2023-12-05T21:58:31Z")

</div>

Hello, I am starting with slim 4, creating an api for my personal project, but I need help, I want to send 3 parameters through the url in this way users/?parameter1=value1&parameter2=value2&parameter3=value3  
Please help, how do I receive them in the routes file with slim 4  
how to get 3 parameters from the url path: /users/?name=jose&login=jlr&passw=12345678 with slim 4

---

<div class="post-metadata">

**Author:** ![robm99x](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@robm99x](https://discourse.slimframework.com/u/robm99x)\
**Post date:** [December 6, 2023, 12:39am UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/2 "2023-12-06T00:39:47Z")

</div>

In Slim 4, you can obtain the entire URI and query params using the request object.

$this-\>request-\>getQueryParams() and you’ll get back an array of name/value pairs.

---

<div class="post-metadata">

**Author:** ![jlramirez](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jlramirez](https://discourse.slimframework.com/u/jlramirez)\
**Post date:** [December 6, 2023, 1:07am UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/3 "2023-12-06T01:07:34Z")

</div>

Thanks friend, do you have an example that I can see?

---

<div class="post-metadata">

**Author:** ![robm99x](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@robm99x](https://discourse.slimframework.com/u/robm99x)\
**Post date:** [December 6, 2023, 1:50pm UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/4 "2023-12-06T13:50:32Z")

</div>

In any Action derived class, you should have an “action()” method where you can write

` $args = $this->request->getQueryParams();`

and this is an array of name/value pairs from your query params.

---

<div class="post-metadata">

**Author:** ![jlramirez](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jlramirez](https://discourse.slimframework.com/u/jlramirez)\
**Post date:** [December 6, 2023, 7:44pm UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/5 "2023-12-06T19:44:20Z")

</div>

Thank you very much Rob Mitchel, I am going to try everything you tell me, thank you for your help and attention. Then I’ll comment and publish it on Slim’s post.

---

<div class="post-metadata">

**Author:** ![jlramirez](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jlramirez](https://discourse.slimframework.com/u/jlramirez)\
**Post date:** [December 7, 2023, 2:34pm UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/6 "2023-12-07T14:34:08Z")

</div>

Hello everyone, thanks to Robm99x for his help, I was able to understand the use of getQueryParams(), I was able to send the parameters through the url, the way I wanted to do it, here I give you my example  
url: http://api\_slim\_base.jl/users/1/test?parametro1=valor1&parametro2=valor2

function in path file: $group-\>get(‘/test’, function ($req, $res, array $args) {  
// $params is an array of all the optional segments  
$params = $req-\>getQueryParams();

```
     $res->getBody()->write("param1: ".$params['parameter1'].", param2: ".$params['parameter2']);
     return $res;
  })->setName('test');

```

With this I consider the issue closed and resolved.

---

<div class="post-metadata">

**Author:** ![jlramirez](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jlramirez](https://discourse.slimframework.com/u/jlramirez)\
**Post date:** [December 7, 2023, 2:47pm UTC](https://discourse.slimframework.com/t/how-to-get-3-parameters-from-the-url-with-slim-4/5767/7 "2023-12-07T14:47:19Z")

</div>

Hello, I also wanted to highlight the other way to receive multiple parameters through the url with slim 4, as the documentation says:  
url example:  
http://api\_slim\_base.jl/users/1/news/Jose/jlr/12345678

function example

$group-\>get(‘/news[/{params:.\*}]’, function ($request, $response, array $args) {  
// $params is an array of all the optional segments  
$params = explode(‘/’, $args[‘params’]);  
//…  
$response-\>getBody()-\>write("Name: “.$params[0].”, login: “.$params[1].”, password: ".$params[2]);  
return $response;  
})-\>setName(‘news’);

Which way is the best?  
Is there any advantage to using one or the other?
