From e7beafaa8b89c7ebbcbe4970241549992a75e3cc Mon Sep 17 00:00:00 2001 From: osaajani Date: Thu, 20 Feb 2020 03:53:15 +0100 Subject: [PATCH] Add 404 page --- .htaccess | 2 +- assets/img/404.svg | 1 + confs/systemd/raspisms.service | 0 controllers/internals/HttpError.php | 29 +++++++++++++++++++++++++++++ index.php | 10 +++++++++- templates/error/404.php | 20 ++++++++++++++++++++ 6 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 assets/img/404.svg mode change 100755 => 100644 confs/systemd/raspisms.service create mode 100644 controllers/internals/HttpError.php create mode 100644 templates/error/404.php diff --git a/.htaccess b/.htaccess index e9ec18d..1704b24 100755 --- a/.htaccess +++ b/.htaccess @@ -1,2 +1,2 @@ RewriteEngine on -RewriteRule "!\.(js|ico|ICO|gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG|css|woff|woff2|ttf|wav|ogg|mp3)$" index.php +RewriteRule "!\.(js|ico|ICO|gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG|css|woff|woff2|ttf|wav|ogg|mp3|svg)$" index.php diff --git a/assets/img/404.svg b/assets/img/404.svg new file mode 100644 index 0000000..fa5892a --- /dev/null +++ b/assets/img/404.svg @@ -0,0 +1 @@ +page not found \ No newline at end of file diff --git a/confs/systemd/raspisms.service b/confs/systemd/raspisms.service old mode 100755 new mode 100644 diff --git a/controllers/internals/HttpError.php b/controllers/internals/HttpError.php new file mode 100644 index 0000000..ab8d32c --- /dev/null +++ b/controllers/internals/HttpError.php @@ -0,0 +1,29 @@ + + * + * This source file is subject to the GPL-3.0 license that is bundled + * with this source code in the file LICENSE. + */ + +namespace controllers\internals; + + /** + * Handler for HTTP errors page + * Not a standard controller as it's not linked to a model in any way. + */ + class HttpError extends \descartes\InternalController + { + /** + * Return 404 error page + */ + public function _404 () + { + http_response_code(404); + $this->render('error/404'); + } + } + diff --git a/index.php b/index.php index cce7e06..7687879 100755 --- a/index.php +++ b/index.php @@ -14,4 +14,12 @@ } //Routing current query - descartes\Router::route(ROUTES, $_SERVER['REQUEST_URI']); + try + { + descartes\Router::route(ROUTES, $_SERVER['REQUEST_URI']); + } + catch (\descartes\exceptions\DescartesException404 $e) + { + $controller = new \controllers\internals\HttpError(); + $controller->_404(); + } diff --git a/templates/error/404.php b/templates/error/404.php new file mode 100644 index 0000000..6df835e --- /dev/null +++ b/templates/error/404.php @@ -0,0 +1,20 @@ +render('incs/head', ['title' => '']) +?> +
+
+
+

Erreur 404, cette page n'existe pas.

+
+ +

+

+ Retour à l'accueil +

+
+
+
+render('incs/footer');