New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BasePath and redirects #1440
Comments
Wont Also in your code sample, why do you declare the local |
Ah I think I see the problem now;
$app->get('/test', function ($request, $response, $args) {
var_dump((string) $request->getUri()->withPath('books'));
// -> http://localhost/dev/slim/index.php/books
$path = $this->router->pathFor('books');
var_dump((string) $request->getUri()->withPath($path));
// -> http://localhost/books
$basePath = $request->getUri()->getBasePath();
var_dump((string) $request->getUri()->withPath($basePath . $path));
// -> http://localhost/dev/slim/index.php/books
// ltrim would work here ...
var_dump((string) $request->getUri()->withPath(ltrim($path, '/')));
// -> http://localhost/dev/slim/index.php/books
});
$app->get('/books', function ($request, $response, $args) {})->setName('books'); Point being the |
Chatting with @JoeBengalen, one idea we've had is making the router basePath aware. This means that Here's one possible implementation: https://github.com/slimphp/Slim/compare/3.x...akrabat:basepath-work?expand=1 is one solution |
Just to add some previous feedback on having this in the past. #838 (comment) I also looked at a similar issue on Silex repo: silexphp/Silex#678 |
I'm beginning to think that basePath is more of a hinderance than a help in Uri!
Consider a very usual use case of a view item page where you want to redirect if the item cannot be found. The basic route callback is:
Now... how do we create the redirect?
I think that if you're using a URL like
http://locahost/slim3/develop-testbed/public/books/2
where the base path is/slim3/develop-testbed/public
, then you have to do this:This is silly! i.e. Surely we can do better?
The text was updated successfully, but these errors were encountered: