-
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
Bug: CodeIgniter\Router\Router hasLocale returns true even if {locale} is absent #3386
Comments
Maybe I don't understand you correctly, but I couldn't reproduce the behavior you're describing here. Please check out the methods that are available in the framework to set Locale dynamically: https://codeigniter.com/user_guide/outgoing/localization.html?highlight=locale#locale-detection I'm closing this but feel free to continue the conversation if you can provide some better example for this issue. |
In Routes.php i have
In App.php I have
i see the Running |
Sorry, but I followed your example and was not able to reproduce the error. Here are my results: When we use When I was checking
This is all working as expected. If I'm still missing something, please don't hesitate to provide another example so I can reproduce the error. |
I managed to reproduce the issue running
diff --git a/app/Config/App.php b/app/Config/App.php
index b91c058..5f6a130 100644
--- a/app/Config/App.php
+++ b/app/Config/App.php
@@ -76,7 +76,7 @@ class App extends BaseConfig
| If false, no automatic detection will be performed.
|
*/
- public $negotiateLocale = false;
+ public $negotiateLocale = true;
/*
|--------------------------------------------------------------------------
@@ -88,7 +88,7 @@ class App extends BaseConfig
| found, the first locale will be used.
|
*/
- public $supportedLocales = ['en'];
+ public $supportedLocales = ['en','it','es','de'];
/*
|--------------------------------------------------------------------------
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 56839ca..aaeca6f 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -20,7 +20,7 @@ $routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
-$routes->setAutoRoute(true);
+$routes->setAutoRoute(false);
/**
* --------------------------------------------------------------------
@@ -32,6 +32,23 @@ $routes->setAutoRoute(true);
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
+$routes->get('/logout', 'Home::index');
+
+
+$routes->group('/admin',function(\CodeIgniter\Router\RouteCollection $routes) {
+ $routes->get('', 'Home::index');
+});
+$routes->group('/{locale}/admin', function(\CodeIgniter\Router\RouteCollection $routes) {
+ $routes->get('', 'Home::index');
+});
+
+$routes->get('/code/(:any)', 'Home::index');
+$routes->get('/menu/(:any)', 'Home::index');
+
+$routes->get('/{locale}', 'Home::index');
+$routes->get('/{locale}/menu/(:any)', 'Home::index');
+
+
/**
* --------------------------------------------------------------------
* Additional Routing
diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php
index 8798cdd..0c3996a 100644
--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -4,7 +4,7 @@ class Home extends BaseController
{
public function index()
{
- return view('welcome_message');
+ return $this->request->getLocale()."\n";
}
//--------------------------------------------------------------------
I'm thinking that the issue is with the |
Okay, now I see it. It's not related to the |
Describe the bug
When using
$this->request->getLocale()
if the route don't have the{lang}
segment i get always the default language because the$this->router->hasLocale()
returns true in system/CodeIgniter.php line 798CodeIgniter 4 version
4.0.4
Affected module(s)
Router
Expected behavior, and steps to reproduce if appropriate
The router should try to match the locale only if {locale} is present
Context
The text was updated successfully, but these errors were encountered: