Cakephp: How would I route all missing controller/action calls to a single, general error page?(Cakephp:我如何将所有丢失的控制器/动作调用路由到一个单一的、通用的错误页面?)
问题描述
我有一个 cakephp 应用程序,每当 Cake 遇到任何错误(缺少控制器、动作等)时,我都会尝试使用它来提供 Pages::404
函数(和相应的视图)).
I've got a cakephp app that I'm trying to get to serve up the Pages::404
function (and corresponding view) whenever Cake encounters any error (missing controller, action, etc).
最好的方法是什么?
推荐答案
Cake 会因缺少方法或控制器而自动抛出 404 错误.在调试模式下,此错误采用包含说明的详细错误消息的形式,例如:
Cake automatically throws a 404 error for missing methods or controllers. While in debug mode, this error takes the form of a detailed error message containing instructions, like:
缺少控制器
错误:找不到 FooController.
Error: FooController could not be found.
错误:在文件中创建下面的类 FooController:>应用程序/控制器/foo_controller.php
Error: Create the class FooController below in file: > app/controllers/foo_controller.php
注意:如果要自定义此错误信息,请创建 app/views/errors/missing_controller.ctp
Notice: If you want to customize this error message, create app/views/errors/missing_controller.ctp
在生产模式 (debug = 0
) 中,消息如下所示:
In production mode (debug = 0
) the message just looks like this:
未找到
错误:在此服务器上找不到请求的地址/foo".
Error: The requested address '/foo' was not found on this server.
这些错误页面在 cake/libs/view/errors/
中定义.正如调试模式中的消息所说,您可以在 app/views/errors/
中创建自己的自定义错误页面(使用与 cake/
目录中的名称相同的名称)代码>.
These error pages are defined in cake/libs/view/errors/
. As the message in debug mode says, you can create your own, custom error pages (using the same name as the ones in the cake/
directory) in app/views/errors/
.
如果您想对错误执行自定义函数,最好将其放入 AppError
控制器中,如 错误处理.
If you want to execute a custom function on errors, you'll best put it in the AppError
Controller as described in Error Handling.
这篇关于Cakephp:我如何将所有丢失的控制器/动作调用路由到一个单一的、通用的错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Cakephp:我如何将所有丢失的控制器/动作调用路由


基础教程推荐
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01