phroute
phroute copied to clipboard
Missing initial '/' with reverse routing
I have a problem with reverse routing. It omits the initial '/', which messes up the URL's when using $router->route('name')
within a URL-subfolder.
$router->post(['/admin/login', 'login.do'], ['MyController','doLogin']);
echo $router->route('login.do');
Expected: /admin/login
Actual: admin/login
Using latest tagged release.
Thanks for the feedback!
The reason this happens is that the router removes all leading slashes - this avoids any ambiguity when resolving the route later so that '/admin/login' and 'admin/login' both resolve to the handler attached to 'admin/login'.
Maybe this was ill-conceived... Not sure how to fix this without breaking BC :)
I'm intending to release a new version which fixes many of the fundamental issues that have been raised since the last release. I'll definitely resolve this one when I do.
Let me know if theres anything else you think I can do in the meantime - I'm happy to try something if we can think of a solution!
Ah. Then I understand why.
I solved it by extending the RouterCollection class. The route()
method simply adds a leading slash, if there isn't one.
Maybe adding a third optional parameter to the route()
-method would do it?
This wouldn't break the current implementation:
public function route($name, array $args = null, $forceLeadingSlash = false)