Add soft 404 error handling with errorController and template

Introduced `errorController` for handling unreachable pages with a soft 404 response. Added configurable error handling via `settings.development.ini` and implemented a new `error.tpl` template. Updated `dispatcher.php` to route non-existent pages to the error controller.
This commit is contained in:
stephan.kasdorf
2025-12-16 14:19:42 +01:00
parent e4462e9402
commit 6e19fb6228
4 changed files with 157 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ final class Dispatcher
public function run()
{
date_default_timezone_set(Config::getInstance()->getConfig()[View::NIBIRU_SETTINGS]['timezone']);
if(Config::getInstance()->getConfig()[self::CONFIG_GENERATOR_SECTION][self::GENERATOR_DATABASE])
{
new Model( false );
@@ -67,5 +68,21 @@ final class Dispatcher
Debug::getInstance();
Display::getInstance()->display();
}
else
{
// Soft 404: Route to error controller for non-existent pages
// Load error controller and template from config [ENGINE] section
$errorControllerName = Config::getInstance()->getConfig()[Engine::T_ENGINE]['error_controller'];
$errorTemplate = Config::getInstance()->getConfig()[Engine::T_ENGINE]['error_template'];
require_once __DIR__ . '/../../application/controller/' . $errorControllerName . 'Controller.php';
$class = "Nibiru\\" . $errorControllerName . "Controller";
$controller = new $class();
$controller->navigationAction();
$controller->pageAction();
Debug::getInstance();
View::getInstance()->display($errorTemplate);
}
}
}