Where do I put a database query in MVC?

前端 未结 5 1421
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 08:41

The last few days, I have extensively read books and web pages about OOP and MVC in PHP, so that I can become a better programmer. I\'ve come upon a little problem in my und

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 09:20

    Model and Entity Classes represents the data and the logic of an application, what many calls business logic. Usually, it’s responsible for:

    1. Storing, deleting, updating the application data. Generally it includes the database operations, but implementing the same operations invoking external web services or APIs is not an unusual at all.
    2. encapsulating the application logic. This is the layer that should implement all the logic of the application

    Here is the MVC Sequence Diagram which shows the flow during a http request:

    enter image description here

    In this case Model is the best place to implement the code realted to access database.

提交回复
热议问题