Thursday, January 21, 2010

Custom 404 error page with CakePHP

1. Create your error layout in app/view/layouts/ (with name error.ctp)
2. Create your 404 error view in app/view/errors/ (with name error404.ctp)
In /cake/libs/view/errors you will find all the default error views.
You can copy and paste error404.ctp in your app/view/errors directory or create a new file and customize this view as you like.
3. Set the error layout in app_controller.php
Then add this to your app_controller.php :
function _setErrorLayout() {
if ($this->name == ‘CakeError’) {
$this->layout = ‘error’;
}
}

function beforeRender () {
$this->_setErrorLayout();
}

1 comment: