duanbin3021 2010-09-10 01:59
浏览 85
已采纳

codeigniter:实体在哪里?

I was wondering what should I do with my entities? For example, a class named Articles, with a few datamembers (name/title/date) and getters & setters. I could add these to my Articles datamember, but it's better practice to seperate those. So what do you think?

Thanks!

  • 写回答

3条回答 默认 最新

  • dongmou2389 2010-09-13 16:20
    关注

    i usually do this:

    1.- create my entity classes in /system/application/classes

    class MyEntity {
    }
    

    2.- define a constant to point to that folder on /system/application/config/constants.php

    define('CLASSES_DIR', APPPATH . "classes/");
    

    3.- include the entities classes from the models:

    require_once(CLASSES_DIR  . "MyEntity.php");
    
    class MyModel extends Model {
    
       function test() {
          $entity = new MyEntity();
          $entity->doSomeStuff();
       }
    
    }
    

    That won't break your mvc structure, and keeps for entities classes separated. Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥200 如何使用postGis实现最短领规划?
  • ¥15 pyinstaller打包错误
  • ¥20 cesm的气溶胶排放文件
  • ¥15 逐月累计,月份不连续,补齐月份
  • ¥15 应用简单的Python代码完成一个学生成绩管理系统
  • ¥15 用matlab求微分方程初值问题
  • ¥15 vscode下编写第三方库opencv与pcl代码时没有代码提示
  • ¥15 能够跑通不报错,如何解决?(标签-matlab)
  • ¥15 MOS在RDS较大,频率高时开关波形异常
  • ¥15 SCENIC分析报错求解答