O'Reilly logo

CakePHP 2 Application Cookbook by Jorge González, James Watts

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error handling

By default, the framework handles most situations where errors occur, displaying an error page to the user when 4xx and 5xx HTTP exceptions are thrown, with a backtrace and code preview when the debug mode is enabled.

In this recipe, we'll see how you can customize this experience for your users and also some more advanced techniques to gain full control over error handling.

Getting ready

As we'll simply use this recipe to demonstrate a custom exception, let's create a controller that will serve as an example. So, create a file named BrokenController.php in app/Controller/, and introduce the following code in it:

<?php
App::uses('AppController', 'Controller');

class BrokenController extends AppController {
}

How to do it...

Perform the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required