Hi,
I want to use parameters when I set a method in container, for exemple 3 parameters on the redirect method :
<?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 :
return $this->container->get('redirect')->($request, $response, 'login');
It’s possible to do something like this ?
Thanks