diff --git a/system/Router/Router.php b/system/Router/Router.php index 1993c60aba30..d79dcb845995 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -15,7 +15,6 @@ use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\Request; use CodeIgniter\Router\Exceptions\RedirectException; -use CodeIgniter\Router\Exceptions\RouterException; /** * Request router. @@ -459,15 +458,12 @@ public function autoRoute(string $uri) { $segments = explode('/', $uri); + // WARNING: Directories get shifted out of the segments array. $segments = $this->scanControllers($segments); - // If we don't have any segments left - try the default controller; - // WARNING: Directories get shifted out of the segments array. - if (empty($segments)) { - $this->setDefaultController(); - } + // If we don't have any segments left - use the default controller; // If not empty, then the first segment should be the controller - else { + if (! empty($segments)) { $this->controller = ucfirst(array_shift($segments)); } @@ -643,8 +639,6 @@ protected function setRequest(array $segments = []) { // If we don't have any segments - try the default controller; if (empty($segments)) { - $this->setDefaultController(); - return; } @@ -662,24 +656,4 @@ protected function setRequest(array $segments = []) $this->params = $segments; } - - /** - * Sets the default controller based on the info set in the RouteCollection. - */ - protected function setDefaultController() - { - if (empty($this->controller)) { - throw RouterException::forMissingDefaultRoute(); - } - - sscanf($this->controller, '%[^/]/%s', $class, $this->method); - - if (! is_file(APPPATH . 'Controllers/' . $this->directory . ucfirst($class) . '.php')) { - return; - } - - $this->controller = ucfirst($class); - - log_message('info', 'Used the default controller.'); - } }