-
Notifications
You must be signed in to change notification settings - Fork 87
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
is_current_url() doesn't take basepath into consideration #199
Comments
Are you instantiating the |
I'm not sure actually, i remember implementing it being a real pain. |
Are you sure this gets called: Because if you look in the |
I didn't know that was possible, nor what that thing does. Gonna have to research more. |
Yes, the basepath works everywhere else, in the base_path() function too |
You should try and do some debugging by putting a As you can see, the base path is taken into consideration there. |
That tells me that the basepath is appended twice.
|
That doesn't give me any insight on what's going on. You will need to debug what's happening in Add those statements in the vendor source files where those files are located. |
$currentUrl = "/path/path/dashboard" $this->uri = $this->basePath = "/path" |
It seems that something is modifying the request URI and adding the basepath to it and it shouldn’t. |
nginx maybe? setting nginx up with subfolders took me days of trial and error, almost nothing worked. maybe there's something in there |
I'll keep it broken though, too much weird stuff to debug. Thanks though. |
Hello @l0gicgate, I think I've run into the same issue, and made a simple test case. Within my Apache DocumentRoot, I created a folder named
The following
And the following
After |
I have the same issue. The base path is applied twice. |
Why?The problem occurs while using slim in the sub-directory. While running slim in a sub-directory the // create app
$app = AppFactory::create();
$app->setBasePath('/project/slim4');
// twig
$twig = Twig::create('.');
// middleware
$app->add(TwigMiddleware::create($app, $twig)) Let's check the path (in middleware or controller/action) public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $args = []) : ResponseInterface
{
exit($request->getUri()->getPath()); # /project/slim4
} The constructor of In $currentUrl = $this->basePath.$this->uri->getPath();
so Solution!This method can be applied to make it work without making any changes to // create app
$app = AppFactory::create();
$app->setBasePath('/project/slim4');
// twig
$twig = Twig::create('.');
// middleware
$app->add(new TwigMiddleware($twig, $app->getRouteCollector()->getRouteParser())); |
I think there is an issue with double invocation when resolving the middleware perhaps.. It'd be great to get a failing test case so we can fix this. |
Funny how I've moved on to a SPA since then, but i hope this gets resolved. |
I have the same issue, configured a nginx as a reverse proxy to my application: https://domain.com/myapp -> http://internal_ip/ In TwigRuntimeExtension::isCurrentUrl:
The solution proposed by @iRaziul worked for me. |
Any news on this issue ? Because the solution proposed by iRaziul not work for me. I use TwigWebpackExtension and it break all links to js and css. I need to set the basePath. |
I have the exact same issue, is there any will to fix it ? |
I can confirm this behavior (bug). Minimal example application: <?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
$app->setBasePath('/slim4-demo');
$twig = Twig::create('.');
$app->add(TwigMiddleware::create($app, $twig));
$app->get('/', function (Request $request, Response $response) {
$view = Twig::fromRequest($request);
$response->getBody()->write($view->fetchFromString('Twig-View current_url: {{ current_url() }}<br>'));
$response->getBody()->write('Request URI Path: ' . $request->getUri()->getPath());
return $response;
});
$app->run(); Running this application on Apache in a sub-directory of the webroot directory URL: http://localhost:8080/slim4-demo/ Actual result
Expected result:
The suggested workaround might work in some situation, but it might cause errors in combination with $app->add(new TwigMiddleware($twig, $app->getRouteCollector()->getRouteParser()));
// ...
$app->get('/', function (Request $request, Response $response) {
$view = Twig::fromRequest($request); // RuntimeException!
// ...
return $response;
}); This would throw an Exception like: So it might not be the best solution for all. The basePath is already part of the request URI. Tested with slim/psr7 and nyholm/psr7. |
When using is_current_url() and a slimphp basepath is set, it won't return true when visiting that route. Removing the basepath fixes it.
The text was updated successfully, but these errors were encountered: