You get the variable as a second parameter in your function
$app->get('hello/{name}', function (Psr\Http\Message\ServerRequestInterface $request, $name) {
var_dump($name);
});
How do I use PSR7 with Lumen and access the HTTP request data?
My code:
$app->bind('Psr\Http\Message\ServerRequestInterface', function ($app) {
return (new Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory)->createRequest($app->make('request'));
});
$app->get('hello/{name}', function (Psr\Http\Message\ServerRequestInterface $request) {
$name = $request->getAttribute('name');
var_dump($name);
});
And then in my URL:
http://example.com/public/hello/world
So with $name = $request->getAttribute('name'); I should get world but I get NULL instead.
Any ideas?
Please or to participate in this conversation.