app/config/routes.php
and must point to the controller/method
that handles the 404 pages. Read more about it in the routing section.HttpNotFoundException
. Fuel will exit for you once it has run the 404 page.throw new HttpNotFoundException;
// Generate the request, execute it and send the output.
try
{
$response = Request::forge()->execute()->response();
}
catch (HttpNotFoundException $e)
{
$route = array_key_exists('_404_', Router::$routes) ? Router::$routes['_404_']->translation : Config::get('routes._404_');
if ($route)
{
// add 'false' to the forge request do disable the routing engine
$response = Request::forge($route, false)->execute()->response();
}
else
{
throw $e;
}
}
_404_ route
points to welcome/404
, let's take a look at that method:// Inside Controller_Welcome
/**
* The 404 action for the application.
*
* @access public
* @return void
*/
public function action_404()
{
$messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?');
$data['title'] = $messages[array_rand($messages)];
// Set a HTTP 404 output header
return Response::forge(Presenter::forge('welcome/404', $data), 404);
}
// Inside your 404 controller
public function action_my404()
{
$original_uri = \Input::uri();
$result = \DB::select()->from('pages')->where('uri', $original_uri)->execute();
if(count($result) === 1)
{
// display that page in whatever way you like
}
else
{
// display your general 404 page
$messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?');
$data['title'] = $messages[array_rand($messages)];
return Response::forge(View::forge('welcome/404', $data), 404);
}
}
a _500_ route
. It allows you to show a proper error message, do additional error logging, or send a notification to an administrator to get the issue fixed.throw new HttpServerErrorException;
HttpNoAccessException
. This exception can be caught in the front controller by defining a _403_ route
. The handler could for example store the current URI, ask for a login, and if a success, return to the stored URI so the user can return to where the violation occured.throw new HttpNoAccessException;