Cakephp:我如何将所有丢失的控制器/动作调用路由到一个单一的一般错误页面? [英] Cakephp: How would I route all missing controller/action calls to a single, general error page?

查看:126
本文介绍了Cakephp:我如何将所有丢失的控制器/动作调用路由到一个单一的一般错误页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cakephp应用程序,我试图得到提供 Pages :: 404 函数(和相应的视图)每遇到Cake遇到任何错误

解决方案



/ div>

Cake自动抛出一个404错误,缺少方法或控制器。在调试模式下,此错误采用包含指令的详细错误消息的形式,如:


缺少控制器



错误:找不到FooController。



错误:在文件中创建类FooController:> app / controllers / foo_controller.php



注意:如果您要自定义此错误消息,请创建应用/ views / errors / missing_controller.ctp


在生产模式( debug = 0 )中,消息看起来像这样:



< blockquote>

找不到



错误:在此伺服器上找不到要求的地址「/ foo」。


这些错误页面在 cake / libs / view / errors / 中定义。由于调试模式下的消息,您可以在 cake / 目录中相同的名称) > app / views / errors / 。



如果您希望在错误时执行自定义函数, code> AppError 控制器,如错误处理中所述。 p>

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).

What's the best way to do that?

解决方案

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:

Missing Controller

Error: FooController could not be found.

Error: Create the class FooController below in file: > app/controllers/foo_controller.php

Notice: If you want to customize this error message, create app/views/errors/missing_controller.ctp

In production mode (debug = 0) the message just looks like this:

Not Found

Error: The requested address '/foo' was not found on this server.

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/.

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:我如何将所有丢失的控制器/动作调用路由到一个单一的一般错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆