PHP-DI and $args


#1

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?


#2

You can ignore $args and use $request->getAttribute('id') instead.


#3

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;
});