dpp3047 2014-04-24 21:46
浏览 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型