1

有没有办法自定义 cakePHP 异常中的 HTTP 错误消息(不是在视图中,而是在 Firebug 和 ajax 响应中显示的那个)?

示例:如果我使用 jQuery ajax 函数调用 URL,我会收到此错误:

"NetworkError: 400 Bad Request - http://test.localhost/test/add"

因为在控制器中我有

if($duplicated){
throw new BadRequestException("Duplicated element!");
}

我想将“错误请求”更改为“重复元素!” 并有类似的东西:

"NetworkError: 400 Duplicated element - http://test.localhost/test/add"

并且(如果可能)如果请求是 ajax,则返回一个空布局。我的代码仅更改标准错误视图中的文本。

提前致谢!

4

1 回答 1

0

CakeResponse::httpCodes($code) might help you. But I don't think you can override any existing error codes.

You might consider then creating your own exception.

于 2011-10-31T14:31:59.890 回答