【发布时间】:2012-11-15 10:48:59
【问题描述】:
我需要提供一个 503 Service Unavailable HTTP 标头。
通常我将这些用于 404 和 500 代码
throw new NotFoundException();
throw new InternalErrorException();
但是我在 CakePHP 2.2 中找不到 503 的相关异常?
在我的“app/lib/AppExceptionHandler.php”文件中,我有这个处理错误的类/函数。
class AppExceptionHandler {
public static function handle($error) {
}
编辑:
-
在“app/Lib”文件夹中,我创建了一个名为“MyExceptions.php”的文件。我在这个文件中写了以下代码:
class ServiceUnavailableException extends CakeException { protected $_messageTemplate = 'Service is not available now'; } -
在“bootstrap.php”中我写了这个:
App::uses('MyExceptions', 'Lib');
-
然后在“MyNewController.php”文件中我写了这个:
抛出新的ServiceUnavailableException("只是尝试");
但是当我抛出这个异常时,我得到了这个错误:
Fatal error: Class 'ServiceUnavailableException' not found in
/var/www/vhosts/example.com/httpdocs/app/Controller/MyNewController.php
on line 3560
Warning (2): Cannot modify header information - headers already sent by
(output started at
/var/www/vhosts/example.com/httpdocs/app/Controller/MyNewController.php:3560)
[APP/Lib/AppExceptionHandler.php, line 19]
我错过了什么? 谢谢
【问题讨论】:
标签: php cakephp exception-handling cakephp-2.0 http-status-code-503