当控制器不存在时 cakePHP 2.0 路由

发布于 2024-12-25 00:41:51 字数 157 浏览 8 评论 0原文

当找不到控制器或插件时。我希望它最终到达一个特定的控制器,该控制器检查 ulr(db),并检查我的 cms 中是否有与其相关的页面。 所以,在默认的 cakephp 路由之后我不想丢失 控制器错误,但我想路由到控制器。 我想保留默认蛋糕路由的所有功能(插件、管理路由)。 我怎样才能做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知你几分 2025-01-01 00:41:51

已编辑
我更改了答案以给出更简洁的解释

创建自定义异常处理程序文件并覆盖 error404 函数。请参阅此文档获取帮助。

<?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
        )
    }
}
?>

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
        )
    }
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文