douou6807 2013-06-06 12:58
浏览 127
已采纳

在PHP MVC项目中在Controller和DAO之间传递数据

I'm working on a PHP MVC project, and the type of data interaction with the database is enough to facilitate the inclusion of a data access layer. The view will use Ajax to pass JSON objects to the controller for processing.

For the controller actions that require executing DAO functions, which is best:

  • Package incoming JSON into model objects and pass to DAO function
  • Pass incoming JSON data directly to DAO

Right now, I'm using option 1, since the views are being developed in parallel to the controller/DAO layers and packing the data within objects is easier for writing tests. When it comes to production, however, I am unsure if this is a good idea.

  • 写回答

2条回答 默认 最新

  • dongtong5242 2013-06-06 13:03
    关注

    Using model objects to transfer data to DAO. The reasons I see are:

    1. Better maintainability
    2. Re-use models elsewhere and in many situations
    3. Have Model specific methods in the model class and Data specific ones in the Data Access layer.
    4. Sending back the model objects in JSON to the View all the time.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料