# Use params in container

**URL:** <https://discourse.slimframework.com/t/use-params-in-container/5491>\
**Category:** Questions\
**Created:** [January 25, 2023, 11:20am UTC](https://discourse.slimframework.com/t/use-params-in-container/5491 "2023-01-25T11:20:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![webcimes](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@webcimes](https://discourse.slimframework.com/u/webcimes)\
**Post date:** [January 25, 2023, 11:20am UTC](https://discourse.slimframework.com/t/use-params-in-container/5491/1 "2023-01-25T11:20:44Z")

</div>

Hi,

I want to use parameters when I set a method in container, for exemple 3 parameters on the redirect method :

```auto
<?php
use DI\Container;
use Slim\Factory\AppFactory;
use Slim\Routing\RouteContext;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

// Create Container
$container = new Container();
AppFactory::setContainer($container);

// Set redirect in Container
$container->set('redirect', function(ServerRequestInterface $request, ResponseInterface $response, string $page)
{
    $routeParser = RouteContext::fromRequest($request)->getRouteParser();
    $url = $routeParser->urlFor($page);
    return $response->withHeader('Location', $url)->withStatus(302);
});

```

and in my middleware or controller class I want to call container method “redirect” and pass my 3 parameters :

```auto
return $this->container->get('redirect')->($request, $response, 'login');

```

It’s possible to do something like this ?

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:** [January 25, 2023, 6:21pm UTC](https://discourse.slimframework.com/t/use-params-in-container/5491/2 "2023-01-25T18:21:21Z")

</div>

Your existing code looks good to me, and it should already work fine.

Note: The (HTTP) request is context specific, and therefore it has been removed from the DI container in Slim 4. The same applies to the request specific route parser.

Your desired syntax would be invalid code, so it also is technically not possible.

---

<div class="post-metadata">

**Author:** ![awstam](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@awstam](https://discourse.slimframework.com/u/awstam)\
**Post date:** [January 27, 2023, 7:30am UTC](https://discourse.slimframework.com/t/use-params-in-container/5491/3 "2023-01-27T07:30:10Z")

</div>

only thing you might want to look at is [PHP-DI - The Dependency Injection Container for humans](https://php-di.org/doc/best-practices.html) (the dont access the container directly part)

---

<div class="post-metadata">

**Author:** ![webcimes](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@webcimes](https://discourse.slimframework.com/u/webcimes)\
**Post date:** [January 27, 2023, 9:49am UTC](https://discourse.slimframework.com/t/use-params-in-container/5491/4 "2023-01-27T09:49:28Z")

</div>

Thanks for your answers, I will try to put this function inside another class and not in the container
