Closed reiniermybeats closed 1 year ago
Hi,
I have the same issue. Any update about it?
Is this really correct @mnapoli?
As stated in the Slim official documentation:
With PSR-7 it is possible to inject objects/values into the request object for further processing. In your applications middleware often need to pass along information to your route closure and the way to do it is to add it to the request object via an attribute.
So you can for example have a middleware which sets in the request an attribute called "user" and have also a route with a "user" named argument, causing PHP-DI Slim bridge to override the original attribute value.
The Slim documented way to access route parameters is with $route->getArgument('id')
function, so maybe the original issue here was the PHP-DI slim bridge documentation indicating a missuse of getAttribute
function.
In the readme example Controllers as a services:
it show to get the route attribute
id
using$request->getAttribute('id')
but if i use this method i getnull
returned.my route is created like this:
and the controller looks like this:
The only way to get the name argument in my case is like this:
I understand I can also get it like this, so it's injected from the __invoke method parameters:
But the readme makes me believe the other way is also possible, somehow.
Is the readme wrong or is there some way to achieve this?