AltoRouter
AltoRouter copied to clipboard
Documentation for setting base path incorrect.
Just a quick edit to the set base path documentation to save some other people the confusion.
It's documented as
$router->setBasePath('/alto-app/');
and what works is only (without the /
):
$router->setBasePath('alto-app');
A bit more details to help out anyone else, and I'll probably submit a pull request later.
The general matcher uses $_SERVER['REQUEST_URI']
which will return a path like:
/foo/bar/?param=value¶m2=value2
If you set this value $router->setBasePath('/alto-app/');
, you end up with this result.
/alto-app//foo/bar/?param=value¶m2=value2
Note those two forward slashes in the route, which won't match anything.
If you do @elliotboney's route, you get this:
alto-app/foo/bar/?param=value¶m2=value2
May or may not be what you want. I set it with $router->setBasePath('/alto-app');
/alto-app/foo/bar/?param=value¶m2=value2
I believe setBasePath('/my-base')
is the correct way. We could just strip the right /
from the path when setting it.
Can confirm, rtrim($base, '/') fixed all my issues.
I think with / and without it's same, but work another. How about fix it?