Tuesday, June 5, 2012

Custom views for errors in CakePHP 2.1

I've been trying to create some custom views for the errors in my cake app. As I'm using v2.1 I have presumed I need to use the Exception Handler.

What I have done so far is:

App::uses('ExceptionRenderer', 'Error');

class AppExceptionRenderer extends ExceptionRenderer {
public function notFound($error) {
$this->controller->layout = null; $this->controller->render('/Errors/error404');
}
}

However all I get is a blank page... I'm guess that this is the wrong way to do this?

Also I've noticed that if I call a 404 using throw new NotFoundException it will call the code above, but if I type in a bad url then it will call the default exception handler... Any ideas why this is happening? I was under the impression they used the same system?

I call the ExceptionRenderer using:

Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'AppExceptionRenderer',
'log' => true
));

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: