In Slim v.3 how can I get args of the route ?
Where args is the array $args of the callable (the params of the pattern of the route)
Thx
In settings
Slim use:
'determineRouteBeforeAppMiddleware' => true,
then in middleware
try this
public function __invoke(Request $request, Response $response, callable $next)
{
$route = $request->getAttribute('route');
$name = $route->getName();
$groups = $route->getGroups();
$methods = $route->getMethods();
// get args in middleware
$arguments = $route->getArguments();
// get params in middleware
$test = $request->getParam('test');
But… How do make this in Slim v4?
Have a look here:
http://www.slimframework.com/docs/v4/middleware/routing.html
Retrieving the current route arguments in Slim 4:
$routeArguments = \Slim\Routing\RouteContext::fromRequest($request)->getRoute()->getArguments();
3 Likes