CakePHP-2.0:当有人在CakePHP-2.0中点击url http:// site / controller / unknownact​​ion时,如何重定向到主页?

时间:2011-10-21 17:18:38

标签: php cakephp cakephp-2.0

http://site/users/abcd

这是错误=>

Error: The action abcd is not defined in controller UsersController

Error: Create UsersController::abcd() in file: app/Controller/UsersController.php.

我想捕获此错误,并重定向到home / index。

我该怎么做?

2 个答案:

答案 0 :(得分:4)

编辑:对不起,我读过了蛋糕 2.0

看看这个http://book.cakephp.org/2.0/en/development/exceptions.html#using-appcontroller-apperror


试用手册manual

class AppError extends ErrorHandler {
    function missingAction($parameters) {
        $this->controller->redirect('/');
    }
}

Error.php包含处理cakePHP错误的函数,你只需覆盖它们

答案 1 :(得分:2)

您可以使用404页面模板并在那里添加HTML重定向。 要修改的文件是:     应用程序/视图/错误/ missing_controller.ctp

更新: 我的坏,如果它缺少一个动作然后更新:     应用程序/视图/错误/ missing_action.ctp