Vizualni Vizualni - 11 months ago 24
PHP Question

How to redirect if controller wasn't found? (cakephp)

This is my routes file. How can I redirect to array('controller' => 'pages', 'action' => 'display', 'home') if controller wasn't found?

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/login', array("controller"=>"user","action"=>"login"));
Router::connect('/settings', array("controller"=>"user","action"=>"settings"));
Router::connect('/logout', array("controller"=>"user","action"=>"logout"));
Router::connect('/video', array("controller"=>"video","action"=>"index"));
Router::connect('/video/page/*', array("controller"=>"video","action"=>"page"));
Router::connect('/video/*', array("controller"=>"video","action"=>"view"));
Router::connect('/upcoming', array("controller"=>"user","action"=>"upcoming"));


This is pretty simple. Create an app_error.php file in your /app directory, (just the way you would for app_model.php or app_controller.php)

Once that is done, put in the following:

class AppError extends ErrorHandler {

    function missingController($params) {
        extract($params, EXTR_OVERWRITE);



Now, this should solve your problem. If you need to invoke components and beforeFilters/Renders, you can call those from the constructor.