When a Controller or Plugin isn't found. I want it to end up at a specific controller that examines the ulr(db), and checks if there's a page related to it in my cms. So, after the default cakephp routing I don't want the missing controller error but I want to route to a controller. I want to keep all the functionality (plugin,admin route) from the default cake route. How can I accomplish this?
Asked
Active
Viewed 944 times
1 Answers
1
Edited I've changed my answer to give a more concise explanation
Create a custom exception handler file and override the error404 function. Reference this documentation for help.
<?php
// 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 extends ExceptionRenderer {
public function error400($error) {
$this->controller->redirect(
//insert redirect code
//it works like any controller redirect, so you should be familiar with the syntax
)
}
}
?>

Scott Harwell
- 7,457
- 2
- 28
- 41
-
Thanks, but how can I get this to work? I placed All the files in the right directories – waterschaats Jan 05 '12 at 19:58
-
Updated answer to see if it helps you. – Scott Harwell Jan 05 '12 at 20:26
-
Sorry, but I still can't get this to work. It doesn't seem to reach the AppExceptionHandler.php, when I put invalid code in this file there's no error. I put everything in the right place – waterschaats Jan 06 '12 at 07:56
-
It's straight from the cakephp documentation. If it doesn't work then you're doing something wrong. However, it's going to be impossible for anyone to help with the problem without seeing your code. – Scott Harwell Jan 06 '12 at 12:53