PHP-DI and $args

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.

1 Like

You can also autowire request attributes by their name:

$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;
1 Like