Using PHP-DI with Slim. When I try to use the $args arg, I’m getting
Unable to invoke the callable because no value was given for parameter 3 ($args)
I guess since it doesn’t know how to autowire that-- what is one to do?
Using PHP-DI with Slim. When I try to use the $args arg, I’m getting
Unable to invoke the callable because no value was given for parameter 3 ($args)
I guess since it doesn’t know how to autowire that-- what is one to do?
You can ignore $args
and use $request->getAttribute('id')
instead.
You can also autowire request attributes by their name:
http://php-di.org/doc/frameworks/slim.html#request-attribute-injection
$app->add(function ($request, $response, $next) {
$request = $request->withAttribute('name', 'Bob');
return $next($request, $response);
});
$app->get('/', function ($name, ResponseInterface $response) { // here $name is autowired
$response->getBody()->write('Hello ' . $name);
return $response;
});