dsb238100 2014-01-26 10:18
浏览 32
已采纳

Codeigniter:如何在我的项目中使用多个'MY_Model'?

I am new to CI and I am maintaining one project build in CI, previously developed by another guy.

This guy create his own MY_Model in application/core and all models he created extend that MY_Model.

I don't like the core model built by him and want to use Jamie Rumbelow's MY_Model instead in the other models I will create recently.

But since almost all the old models extended the MY_Model already, I can't just replace MY_Model.

How can I use Jamie Rumbelow's MY_Model' and still make old models work?

Thanks for any advices!

  • 写回答

1条回答 默认 最新

  • doufuxi7093 2014-01-26 14:39
    关注

    You'd have to rename one of the MY_Model classes and put both of them in the MY_Model.php file (or include the renamed one from there). For example, if you were to rename Jamie Rumbelow's class to JR_Model instead, here's how your MY_Model.php file would look like:

    class MY_Model extends CI_Model {
        // your predecessor's code
    }
    
    class JR_Model extends CI_Model {
        // Jamie Rumbelow's code
    }
    

    ... then you can extend from JR_Model wherever you like, without breaking your old models.

    Note that it's important to keep the filename as 'MY_Model.php', because that's what CodeIgniter will look for when loading a CI_Model extension.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件