CakePHP 1.3 still offers support for PHP4, yet most CakePHP applications are built exclusively for PHP5. Therefore, it is only expected that our applications use language features only available in PHP5, such as exceptions.
However, there is no built-in support in CakePHP to handle exceptions. This recipe shows us how to create a base exception class that can be used throughout our application, and how to properly recover the application workflow after an exception is thrown.
We need a basic application skeleton to work with. Follow the entire recipe Detecting file types with MagicDb.
1. Edit your
app/controllers/uploads_controller.php
file and change theview()
anddownload()
methods, so that where it reads:$this->cakeError('error404');
It now reads:
throw new AppException('Upload '.$id.' not found');
2. Create a file named
app_exception.php
and place it in yourapp/
folder, with the following contents:<?php class AppException...