nikic / FastRoute

Fast request router for PHP
Other
5.13k stars 445 forks source link

How can I add a parameter to the handler not from the route? #197

Closed rud99 closed 5 years ago

rud99 commented 5 years ago

My code: $dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) { $r->addRoute('GET', '/part1', ['App\Controllers\HomeController', 'parts']); $r->addRoute('GET', '/part2', ['App\Controllers\HomeController', 'parts']); }); it is necessary to find out from which route the request came

lcobucci commented 5 years ago

@rud99 what exactly do you need about the route, only the URI? If so, you can rely on $_SERVER['REQUEST_URI'].

If you're using FastRoute as part of a framework (like Zend Expressive) then you can use the PSR-7 request to get the URI or the matched route (as a request attribute) - the latter depends on what you're using.

rud99 commented 5 years ago

lcobucci, thanks for the info! You have prompted me to a decision!

lcobucci commented 5 years ago

@rud99 glad to help :+1: