diff --git a/system/Router/Router.php b/system/Router/Router.php index 91c399edfa44..fc2c178fdb67 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -548,11 +548,13 @@ public function autoRoute(string $uri) $this->params = $segments; } + $defaultNameSpace = $this->collection->getDefaultNamespace(); + $controllerName = $this->controllerName(); if ($this->collection->getHTTPVerb() !== 'cli') { - $controller = '\\' . $this->collection->getDefaultNamespace(); + $controller = '\\' . $defaultNameSpace; $controller .= $this->directory ? str_replace('/', '\\', $this->directory) : ''; - $controller .= $this->controllerName(); + $controller .= $controllerName; $controller = strtolower($controller); $methodName = strtolower($this->methodName()); @@ -575,7 +577,7 @@ public function autoRoute(string $uri) } // Load the file so that it's available for CodeIgniter. - $file = APPPATH . 'Controllers/' . $this->directory . $this->controllerName() . '.php'; + $file = APPPATH . 'Controllers/' . $this->directory . $controllerName . '.php'; if (is_file($file)) { include_once $file; @@ -583,9 +585,9 @@ public function autoRoute(string $uri) // Ensure the controller stores the fully-qualified class name // We have to check for a length over 1, since by default it will be '\' - if (strpos($this->controller, '\\') === false && strlen($this->collection->getDefaultNamespace()) > 1) + if (strpos($this->controller, '\\') === false && strlen($defaultNameSpace) > 1) { - $this->controller = '\\' . ltrim(str_replace('/', '\\', $this->collection->getDefaultNamespace() . $this->directory . $this->controllerName()), '\\'); + $this->controller = '\\' . ltrim(str_replace('/', '\\', $defaultNameSpace . $this->directory . $controllerName), '\\'); } }