Removed the header() calls from the class to add more flexibility to 404 and 405 routes
This commit is contained in:
parent
8e5fb1157a
commit
6b9c6bbf6d
|
@ -93,12 +93,10 @@ class Route {
|
||||||
if (!$route_match_found) {
|
if (!$route_match_found) {
|
||||||
// But a matching path exists
|
// But a matching path exists
|
||||||
if ($path_match_found) {
|
if ($path_match_found) {
|
||||||
header('HTTP/1.0 405 Method Not Allowed');
|
|
||||||
if (self::$methodNotAllowed) {
|
if (self::$methodNotAllowed) {
|
||||||
call_user_func_array(self::$methodNotAllowed, Array($path,$method));
|
call_user_func_array(self::$methodNotAllowed, Array($path,$method));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
header('HTTP/1.0 404 Not Found');
|
|
||||||
if (self::$pathNotFound) {
|
if (self::$pathNotFound) {
|
||||||
call_user_func_array(self::$pathNotFound, Array($path));
|
call_user_func_array(self::$pathNotFound, Array($path));
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,10 @@ Route::add('/this-route-is-defined', function() {
|
||||||
|
|
||||||
// Add a 404 not found route
|
// Add a 404 not found route
|
||||||
Route::pathNotFound(function($path) {
|
Route::pathNotFound(function($path) {
|
||||||
|
// Do not forget to send a status header back to the client
|
||||||
|
// The router will not send any headers by default
|
||||||
|
// So you will have the full flexibility to handle this case
|
||||||
|
header('HTTP/1.0 404 Not Found');
|
||||||
navi();
|
navi();
|
||||||
echo 'Error 404 :-(<br>';
|
echo 'Error 404 :-(<br>';
|
||||||
echo 'The requested path "'.$path.'" was not found!';
|
echo 'The requested path "'.$path.'" was not found!';
|
||||||
|
@ -132,6 +136,10 @@ Route::pathNotFound(function($path) {
|
||||||
|
|
||||||
// Add a 405 method not allowed route
|
// Add a 405 method not allowed route
|
||||||
Route::methodNotAllowed(function($path, $method) {
|
Route::methodNotAllowed(function($path, $method) {
|
||||||
|
// Do not forget to send a status header back to the client
|
||||||
|
// The router will not send any headers by default
|
||||||
|
// So you will have the full flexibility to handle this case
|
||||||
|
header('HTTP/1.0 405 Method Not Allowed');
|
||||||
navi();
|
navi();
|
||||||
echo 'Error 405 :-(<br>';
|
echo 'Error 405 :-(<br>';
|
||||||
echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';
|
echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user