Files
nibiru-framework.com/application/controller/errorController.php
stephan.kasdorf 6e19fb6228 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.
2025-12-16 14:19:42 +01:00

53 lines
1.5 KiB
PHP
Executable File

<?php
namespace Nibiru;
/**
* Class errorController
* @project prod.maschinen-stockert.de
* @desc Soft 404 error page handler for unreachable pages
* @author Claude Code / Stephan Kasdorf
* @date Dec 16 2024
* @package Nibiru
*/
use Nibiru\Adapter\Controller;
use Nibiru\Module\{
Assetmanager\Plugins\Assetmanager,
Cms\Plugins\Cms,
Errorhandler\Plugins\Errorhandler
};
class errorController extends Controller
{
private string $requestedUri = '';
public function __construct()
{
// Store the originally requested URI before routing to error
$this->requestedUri = $_SERVER['REQUEST_URI'] ?? '/';
}
public function pageAction()
{
// Set HTTP status code to 404 (while still rendering the page - soft 404)
http_response_code(404);
// Assign error-specific variables
View::assign([
'requestedUri' => htmlspecialchars($this->requestedUri, ENT_QUOTES, 'UTF-8'),
'errorCode' => '404',
'errorTitle' => 'Seite nicht gefunden',
'errorMessage' => 'Die angeforderte Seite konnte leider nicht gefunden werden.',
'errorSuggestion' => 'Die Seite wurde möglicherweise verschoben, gelöscht oder existiert nicht mehr.',
'metaRobots' => 'noindex, follow',
'homeUrl' => '/',
'contactUrl' => '/kontakt',
'machinesUrl' => '/maschinen'
]);
}
public function navigationAction()
{
JsonNavigation::getInstance()->loadJsonNavigationArray();
}
}