我有一个 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:我如何将所有丢失的控制器/动作调用路由到一个单一的、通用的错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
不能使用 'Object 作为类名,因为它是保留的Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作为类名,因为它是保留的 Cake 2.2.x)
OAuth 重定向后会话丢失Session is lost after an OAuth redirect(OAuth 重定向后会话丢失)
Cakephp 3.x 中的分页排序Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分页排序)
CakePHP 多个应用程序的共享核心CakePHP Shared core for multiple apps(CakePHP 多个应用程序的共享核心)
在 CakePHP 3 上登录 [ Auth->identify() ] 始终为 falLogin [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登录 [ Auth-identify() ] 始终为 false)
致命错误:允许的内存大小为 134217728 字节已用尽Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命错误:允许的内存大小为 134217728 字节已用尽