diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index ef965d0d8df5..4bde1c042b6d 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -451,7 +451,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache $uri = $this->determinePath(); - if ($this->enableFilters && $this->checkControllerNotFoundBeforeFilter()) { + if ($this->enableFilters) { // Start up the filters $filters = Services::filters(); @@ -1159,22 +1159,4 @@ protected function outputBufferingEnd(): string return $buffer; } - - /** - * Check whether the controller is not found before the before filter. - */ - protected function checkControllerNotFoundBeforeFilter(): bool - { - // Check whether the controller type is Closure. - if (is_object($this->controller) && (get_class($this->controller) === 'Closure')) { - return true; - } - - // Try to autoload the class - if (! class_exists($this->controller, true) || $this->method[0] === '_') { - throw PageNotFoundException::forControllerNotFound($this->controller, $this->method); - } - - return true; - } } diff --git a/system/Router/AutoRouter.php b/system/Router/AutoRouter.php index f7cd02a3d329..918653633037 100644 --- a/system/Router/AutoRouter.php +++ b/system/Router/AutoRouter.php @@ -174,6 +174,11 @@ public function getRoute(string $uri, string $httpVerb): array ); } + // Check if the controller exists. + if (! class_exists($this->controller, true) || $this->method[0] === '_') { + throw PageNotFoundException::forControllerNotFound($this->controller, $this->method); + } + return [$this->directory, $this->controllerName(), $this->methodName(), $params]; } diff --git a/user_guide_src/source/changelogs/v4.4.2.rst b/user_guide_src/source/changelogs/v4.4.2.rst index 19f2a4f1782c..9351a3791fc1 100644 --- a/user_guide_src/source/changelogs/v4.4.2.rst +++ b/user_guide_src/source/changelogs/v4.4.2.rst @@ -12,6 +12,8 @@ Release Date: Unreleased BREAKING ******** +- **AutoRouting Legacy:** Add a condition to check if the controller exists. + Message Changes ***************