Yii 在 config/main.php 中更改 errorHandler 的类 [英] Yii change class of errorHandler in config/main.php
问题描述
我创建了一个从 CErrorHandler 扩展的自定义错误处理程序类 (CMyErrorHandler).
I've created a Custom error handler class (CMyErrorHandler) that extends from CErrorHandler.
然而,当我在 config/main.php 中将 errorHandler 组件的类配置为 CMyErrorHandler 时,Yii 似乎仍然使用旧的 CErrorHandler 类.
However when I configure the class of the errorHandler component in config/main.php to be CMyErrorHandler, Yii still seems to be using the old CErrorHandler class.
'errorHandler'=>array(
'errorAction'=>'site/error',
'class' => 'application.components.CMyErrorHandler',
),
我如何才能使用我的自定义错误处理程序?谢谢!
How can I manage to use my Custom error handler? Thanks!
推荐答案
我找到了问题的根源.我无法扩展 CErrorHandler 并且只覆盖我需要的两个方法(handleError 和 handleException),因为这些方法使用私有变量 un CErrorHandle,它在扩展类 CMyErrorHandle 中不可访问.我相信这是由于 Yii 的 CErrorHandle 类中的糟糕设计(尽管我必须说我非常喜欢这个框架).因此,我选择复制粘贴整个类并在两种方法中进行我需要的更改.在这些之后,一切都按预期进行.
I found the source of my problem. I's not possible to extend CErrorHandler and just override the two methods I needed (handleError and handleException), because these methods use a private variable un CErrorHandle which is not accessible in the extended class CMyErrorHandle. I believe this is due to a bad design in Yii's CErrorHandle class (though I must say I absolutely love the framework). Therefore I opted to copy paste the whole class and make the changes I needed in both methods. After these everything worked as expected.
这篇关于Yii 在 config/main.php 中更改 errorHandler 的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!