我试图将所有错误强制到 Cakephp(2.0) 中的单个自定义页面,但我发现的大多数教程都是针对非常具体的错误代码的。我希望它只显示一个错误页面,所以我首先要做的是将特定错误状态的所有错误指向一个错误页面。但经过进一步测试,我注意到其他代码没有被捕获。
我需要我的代码将所有 http 错误代码捕获到单个错误页面。
这是我的代码:
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'AppExceptionRenderer',
'log' => true
));
还有我的 AppExceptionRenderer:
<?php
App::uses('ExceptionRenderer', 'Error');
class AppExceptionRenderer extends ExceptionRenderer {
public function internalError($error) {
$this->controller->beforeFilter();
$this->controller->set('title_for_layout', 'Internal Server Error');
$this->controller->render('/Errors/error500');
$this->controller->response->send();
... All the other error handlers are similar to this, but very limited since there are a lot of client and server errors
} ?>
我的模板页面似乎工作得很好,所以我没有包含它。
如何更改代码以覆盖每个 http 状态代码?还是不可能?