I checked this question and this cookbook section.
I created such code and made this steps:
In app/Config/core.php
Configure::write('Exception.handler', 'AppExceptionHandler::handle');
In app/Config/bootstrap.php
App::uses('AppExceptionHandler', 'Lib');
In app/Lib/AppExceptionHandler.php
class AppExceptionHandler {
public static function handle($error) {
$errorCode = $error->getCode();
if ($errorCode == 404) {
header("HTTP/1.0 404 Not Found");
} elseif ($errorCode == 500) {
header("HTTP/1.0 500 Internal Server Error");
}
echo "here is something is wrong";
}
}
Everything works fine except the rendering part.
To this time I can only write "something is wrong" but I can't make it viewed inside a view file.
Inside "App/Controller" folder I have "ErrorsController.php".
I need to run ErrorsController when I get an exception. So I will render inside that controller's view files.
Edit:
class ErrorsController extends AppController {
function beforeFilter() {
if ( isset($this->request->params['pass'][0]) ) {
if ($this->request->params['pass'][0] == "404") {
$this->response->statusCode('404');
}
}
}
public function index($typeOfError) {
echo "here I am $typeOfError";
}
}
When I enter to example.com/errors/index/404
the output is "here is something is wrong" but I need it to be "here I am 404". Because when I enter to ErrorsController's action and send 404 header, I am redirected to AppHandler's handle. So how can I render my own view?
This problem is still exists..