-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
App\Config\Routes loaded twice #2203
Comments
Just did a quick scan of the codebase and it only appears to be loaded once. The only way I can think of this happening otherwise is when it scans any namespaces for additional routes files it's not ignoring those two. I'll try to look into this in the next few days. |
Cannot reproduce. Added:
Into my routes file. Fired up the server ( |
Is this on a clean install? You don't maybe have a helper being loaded with a similarly named function do you? |
Yes clean install . Just downloaded the latest version from here. |
@web-media what happens if you comment out the toolbar in |
Can you change it to this to get a little more helpful feedback on the what and when:
|
→ Called from /ci/app/Config/Routes.php:76 |
Can you run it from CLI and put the output in PasteBin (or anywhere easier to read)?
|
Initial reactions have me weirded out. I only see one Trace call in your screenshot when there should have been two, and unless I'm misunderstanding the parser I think that |
The only thing that came to my mind is that RouteCollection method discoverRoutes doesn't do the job somehow in this lines if ($file === APPPATH . 'Config/Routes.php')
{
continue;
} protected function discoverRoutes()
{
if ($this->didDiscover)
{
return;
}
// We need this var in local scope
// so route files can access it.
$routes = $this;
if ($this->moduleConfig->shouldDiscover('routes'))
{
$files = $this->fileLocator->search('Config/Routes.php');
foreach ($files as $file)
{
// Don't include our main file again...
if ($file === APPPATH . 'Config/Routes.php')
{
continue;
}
include $file;
}
}
$this->didDiscover = true;
} |
Can we get some stats from you? I just tried again with a fresh clone, adding a function to Could you provide:
And any other information you can think to provide. UPdate: Realized I was in production mode when I tried that. So copied For reference, I'm on Mac 10.4.5, running PHP 7.2.7, using CI's built-in server, and REQUEST_URI as the protocol. |
XAMPP for Windows 7.3.7 Commenting this line //include $file; if ($file === APPPATH . 'Config/Routes.php')
{
continue;
} protected function discoverRoutes()
{
if ($this->didDiscover)
{
return;
}
// We need this var in local scope
// so route files can access it.
$routes = $this;
if ($this->moduleConfig->shouldDiscover('routes'))
{
$files = $this->fileLocator->search('Config/Routes.php');
foreach ($files as $file)
{
// Don't include our main file again...
if ($file === APPPATH . 'Config/Routes.php')
{
continue;
}
//include $file;
}
}
$this->didDiscover = true;
} |
$file is N:\a\htdocs\ci\system/\Config/Routes.php
N:\a\htdocs\ci\app\/\Config/Routes.php" is compared to N:\a\htdocs\ci\app\Config/Routes.php APPPATH |
Awesome. At least we can pinpoint what needs work. Thanks for sticking with it and helping us locate that! |
If you happen to create a PR with a fix, that'd be awesome. Might be a few days until I have time to really dig in, especially with needing to update my Windows install and get it working for this again. |
you're welcome ! always glad to help . |
No better way to learn :D |
Correct cleaning of namespaces in FileLocater for better Windows compatibility. See #2203
@web-media Just merged a fix for that. Please pull down the latest and let me know if it works for you. |
Solved . |
I solved it by changing |
I'm using version 4.1.3 and noticed the same issue. |
Still happening to me with 4.1.8 |
@livelogic What value is in the
|
@kenjis: yes, that seem to be the culprit. BTW, upgraded to 4.1.9 but nothing is different regarding this issue.
These paths have backslashes as directory separators, as expected in Windows environment, but the culprit line compares a path that has a Linux pattern appended:
So, instead of commenting the line:
i tried this:
and things work fine (app\Config\Routes.php is loaded only once). I also notice another strange thing in the same method: it loads unconditionally the system\Config\Routes.php file via include, although this file has already been loaded by app\Config\Routes.php, via require:
Double-loading this file doesn't seem harmful, still it doesn't seem like intended behavior. |
@livelogic Thank you for the info. |
@livelogic Thank you for confirming. |
Is this still an issue? Ran into it on v4.4.1, and it seems to be the same behavior. If I comment out |
If you use Windows, it may be another bug. See #7930 |
Yes, can confirm the DIRECTORY_SEPARATOR solves this issue |
Describe the bug
App\Config\Routes file is loaded twice
CodeIgniter 4 version
All -Latest
Affected class
RouteCollection.
Codeigniter
Codeigniter->run () ---> handleRequest() --->tryToRouteIt () = require APPPATH .'Config/Routes.php';
** steps to reproduce **
Add a function to App\Config\Routes file
The text was updated successfully, but these errors were encountered: