# Getting parameter action function Slim 4

**URL:** <https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264>\
**Category:** Questions\
**Created:** [May 19, 2022, 5:38am UTC](https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264 "2022-05-19T05:38:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vosky](https://avatars.discourse-cdn.com/v4/letter/v/d6d6ee/32.png) [@vosky](https://discourse.slimframework.com/u/vosky)\
**Post date:** [May 19, 2022, 5:38am UTC](https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264/1 "2022-05-19T05:38:07Z")

</div>

I got an action route like this

```auto
`$app->get('/company/{id}', GetCompany::class);`

```

And the Action

```auto

```

class GetCompany extends Action  
{  
protected function action(): Response  
{

```
    return $this->respondWithData(....);
}

```

}

```auto

```

How do I get the {id} inside the action() function?

Thanks

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [May 19, 2022, 7:44am UTC](https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264/2 "2022-05-19T07:44:00Z")

</div>

This would work if you use the `__invoke` method instead of the `action()` method as name.

Example:

```php
<?php

namespace App\Action\Home;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class HomeAction
{
    public function __invoke(
        ServerRequestInterface $request,
        ResponseInterface $response,
        array $args
    ): ResponseInterface {
        $id = $args['id'];
        
        $response->getBody()->write(sprintf('The ID is: %s', $id));

        return $response;
    }
}

```

---

<div class="post-metadata">

**Author:** ![vosky](https://avatars.discourse-cdn.com/v4/letter/v/d6d6ee/32.png) [@vosky](https://discourse.slimframework.com/u/vosky)\
**Post date:** [May 19, 2022, 11:53pm UTC](https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264/3 "2022-05-19T23:53:26Z")

</div>

Thanks don’t you need to implement the “actions” class there?

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [May 20, 2022, 7:02am UTC](https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264/4 "2022-05-20T07:02:11Z")

</div>

Do you mean the “action” class method?

My example shows an “invokable” class. Slim will pass the request, response and the route arguments to the `__invoke ` method if you use define the route like this: `$app->get('/company/{id}', GetCompany::class);`

---

<div class="post-metadata">

**Author:** ![vosky](https://avatars.discourse-cdn.com/v4/letter/v/d6d6ee/32.png) [@vosky](https://discourse.slimframework.com/u/vosky)\
**Post date:** [May 20, 2022, 11:56pm UTC](https://discourse.slimframework.com/t/getting-parameter-action-function-slim-4/5264/7 "2022-05-20T23:56:38Z")

</div>

This can be marked as resolved.  
I only need in which folder this class should be. I will open a new thread.  
Thanks
