Reputation: 352
I know how to make response routes in the actual /config/routes.php file, but I can't find where to change the default 'fetal dispatcher' error. I'd like to be able to have it route to a nice 404 page I've made when there's a missing page/action controller. Is that possible?
Upvotes: 1
Views: 358
Reputation: 5642
Yes, you can take advantage of lithium\core\ErrorHandler
for this. See the code in the default config/bootstrap/errors.php
:
ErrorHandler::apply('lithium\action\Dispatcher::run', array(), function($info, $params) {
$response = new Response(array(
'request' => $params['request'],
'status' => $info['exception']->getCode()
));
Media::render($response, compact('info', 'params'), array(
'library' => true,
'controller' => '_errors',
'template' => 'development',
'layout' => 'error',
'request' => $params['request']
));
return $response;
});
This is saying, if any exception occurs during Dispatcher::run()
, display the development.html.php
template from the views/_errors
folder with the layouts/error.html.php
layout.
So you can change that -- maybe you check the Environment
to see if this is a dev or production environment and display a different template for production.
Maybe if $info['exception']->getCode() === 404
, you can switch to a template specifically for 404 errors.
Upvotes: 2