dpp3047 2014-04-24 21:46 采纳率: 0%
浏览 78

覆盖Yii 1.1.14框架类而不替换它们

I have some custom logic I need to insert into CDbCommand, CDbTransaction & CActiveRecord classes that comes with the Yii framework. I can't replace them because I am using the same framework files for other projects.

Most of my models are already generated and is extended from CActiveRecord. I know I can easily switch them to my own custom class extended from CActiveRecord. However, the methods that I want to override in CDbCommand would not be filtered into CActiveRecord if I extend the CDbCommand class, and in addition CDbCommand is used by many other Framework classes. I need all other framework classes to use my overrides of CDbCommand methods.

Any ideas?

  • 写回答

3条回答 默认 最新

  • douzhi3586 2014-04-28 06:12
    关注

    There has been a similar question in the yii forums, concerning classes like CHtml, which are caled statically all over the framework and in generated Code.

    There seems to be no pretty way, the kind-of-consensus in the discussion was to do the following (example CHtml):

    Move CHtml.php to Html.php and rename the class to Html. Create a new, empty CHtml class, that extends Html. Add your overwrites to the new CHtml class.

    It's not pretty but it works and is reasonably maintanable on Yii updates.

    评论

报告相同问题?