Is there a nice and supported way to define routes like this:
$app->get('/', function (Request $request, Response $response) {
});
$app->get('/hello/{name}', function (Request $request, Response $response) {
});
... and get them work as expected no matter the location of the index.php
routing file?
E.g. if DOCUMENT_ROOT
is C:\Projects\Playground
(http://playground.example.com
) and my router file is located at C:\Projects\Playground\PHP\Slim\foo\bar\index.php
(http://playground.example.com/PHP/Slim/foo/bar
) I'd like http://playground.example.com/PHP/Slim/foo/bar/hello/world!
to match '/hello/{name}'
.
(Every other file belonging to Slim would be somewhere else, let's say C:\Libraries\Slim
, and should be irrelevant to this question.)
With nice and supported I mean not this:
$uri_prefix = complex_function_to_calculate_it($_SERVER['DOCUMENT_ROOT'], __DIR__);
$app->get($uri_prefix . '/hello/{name}', function (Request $request, Response $response) {
});
Slim 3 uses nikic/fast-route but I couldn't find any hint.