Add a 404 custom controller option on Router.

This commit is contained in:
kj 2021-03-25 12:02:50 -04:00
parent 8d418c8eb9
commit d23ecfbde6

View File

@ -21,6 +21,7 @@ class Router {
private static $put = []; private static $put = [];
private static $delete = []; private static $delete = [];
private static $last; private static $last;
public static $notFoundCallBack;
private function __construct() {} private function __construct() {}
@ -295,8 +296,13 @@ class Router {
return; return;
} }
} }
if (isset(static::$notFoundCallBack))
call_user_func_array(static::$notFoundCallBack, []);
else {
header("HTTP/1.0 404 Not Found"); // Si no hay router que coincida, se devuelve error 404 header("HTTP/1.0 404 Not Found"); // Si no hay router que coincida, se devuelve error 404
echo '<h2 style="text-align: center;margin: 25px 0px;">Error 404 - Página no encontrada</h2>'; echo '<h2 style="text-align: center;margin: 25px 0px;">Error 404 - Página no encontrada</h2>';
} }
}
} }
?> ?>