Marc Rasmussen
Marc Rasmussen

Reputation: 20555

Cakephp redirect on error

So we all know these Error missing controller or any other error that CakePHP can throw.

Now my question may be fairly simple but i could not find any documentation on the subject.

How do i redirect to a 404 not found or a 500 execption page (meaning how do i redirect to a costum page) if an execption should be found?

in my config/core.php i found this:

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

However im not sure what i should change it to?

Upvotes: 2

Views: 2836

Answers (1)

user2964568
user2964568

Reputation: 104

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

Create file Cake/Error/Test.php

<?php
class Test {
    public function __construct(Exception $exception) {
        header('Location: /');die();
    }
}

Missing Controller error you can prevent with router. Create last router rule:

Router::connect('/*', array('controller' => 'app', 'action' => 'e404'));    

Upvotes: 3

Related Questions