# Nested group parameters? Am I doing it wrong?

**URL:** <https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83>\
**Category:** Questions\
**Created:** [April 5, 2016, 4:43pm UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83 "2016-04-05T16:43:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesHeald](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jamesheald/32/52_2.png) [@JamesHeald](https://discourse.slimframework.com/u/JamesHeald)\
**Post date:** [April 5, 2016, 4:43pm UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83/1 "2016-04-05T16:43:30Z")

</div>

Im developing a RESTFUL api with Slim and Im trying to work out how to get nested group parameters working.

Lets say I have a route like so:

/users/james/images/218/comments

Im going to want to group these up like so:

users(uid)-\>images(id)-\>comments(\*offset)…

How would I go about doing this?

Thanks.

---

<div class="post-metadata">

**Author:** ![akrabat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/akrabat/32/9_2.png) [@akrabat](https://discourse.slimframework.com/u/akrabat)\
**Post date:** [April 5, 2016, 8:40pm UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83/2 "2016-04-05T20:40:07Z")

</div>

I"m sorry, but I don’t understand what you mean by grouping them up.

The route would look something like

```auto
$app->get('/users/{user_id}/images/{image_id}/comments', function($request, $response, $args) {
    $userId = $args['user_id'];
    $imageId = $args['image_id'];

    // do something here and return $response
});

```

---

<div class="post-metadata">

**Author:** ![JamesHeald](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jamesheald/32/52_2.png) [@JamesHeald](https://discourse.slimframework.com/u/JamesHeald)\
**Post date:** [April 6, 2016, 6:38pm UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83/3 "2016-04-06T18:38:17Z")

</div>

I just thought it would probably be best to make use of Slims grouping function like so:

```
$app->group("/users/:user_id", function() use($app){
    $app->group("/images/:img_id", function() use($app){
        $app->get("/comments, function() use($app){
            // How do I get the parent groups paremeters from here? I know I can get my first parent, but what about my second parent?
        });
    });
});
```

---

<div class="post-metadata">

**Author:** ![akrabat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/akrabat/32/9_2.png) [@akrabat](https://discourse.slimframework.com/u/akrabat)\
**Post date:** [April 6, 2016, 6:52pm UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83/4 "2016-04-06T18:52:24Z")

</div>

In Slim 3, this just works:

```php
$app->group("/users/{user_id}", function() {
    $this->group("/images/{img_id}", function() {
        $this->get("/comments", function($request, $response, $args) {
            $userId = $args['user_id'];
            $imageId = $args['img_id'];
        });
    });
});

```

No idea about Slim 2, sorry.

---

<div class="post-metadata">

**Author:** ![JamesHeald](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/jamesheald/32/52_2.png) [@JamesHeald](https://discourse.slimframework.com/u/JamesHeald)\
**Post date:** [April 6, 2016, 7:04pm UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83/5 "2016-04-06T19:04:32Z")

</div>

This is probably due to the fact Im using Slim 2, looks like Il be upgrading, then.

Cheers.

---

<div class="post-metadata">

**Author:** ![silentworks](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/silentworks/32/10_2.png) [@silentworks](https://discourse.slimframework.com/u/silentworks)\
**Post date:** [May 6, 2016, 11:01am UTC](https://discourse.slimframework.com/t/nested-group-parameters-am-i-doing-it-wrong/83/6 "2016-05-06T11:01:37Z")

</div>

They should be continuously passed down.

```php
$app->group("/users/:user_id", function() use($app){
    $app->group("/images/:img_id", function() use($app){
        $app->get("/comments", function($user_id, $img_id) use($app){
            var_dump($user_id, $img_id);
        });
    });
});

```
