About thinkphp, I think the official demon has written the business logic in the action. The model is only used for verification and Automatic completion. However, some of them are mixed writes of action and model, I read thinkphp projects on github, but they are almost all written. Some write the model in the action... about thinkphp, I think the official demon has written the business logic in the action. The model is only used for verification and Automatic completion. However, some of them are mixed writes of action and model, I read thinkphp projects on github, but they are almost all written. Some write actions and some write models. Where should I write the business logic in the thinkphp framework?
Reply content:
About thinkphp, I think the official demon has written the business logic in the action. The model is only used for verification and Automatic completion. However, some of them are mixed writes of action and model, I read thinkphp projects on github, but they are almost all written. Some write actions and some write models. Where should I write the business logic in the thinkphp framework?
The basic idea is the traditional MVC (Model, View, Controller)
Generally, the Controller is responsible for the business logic.
View is responsible for processing data display
Controller is used to process application data logic.
Why?
Helps you manage complex applications because you can focus on one aspect within a period of time.
MVC layering also simplifies group development. Different developers can develop views, controller logic, and business logic at the same time.
The model was born to solve the problem.
For you. If you do it by yourself. Exercise. You can write according to your habits. This does not matter.
But I think it is best to develop a habit. This separation is clear and easy to understand. It is also good for you to collaborate with other projects in the future.
If you work together, you need to work in different layers.
You can refer to Baidu for a clear picture.
The author does not seem to understand MVC completely. In thinkphp, m and c are not strictly divided. You can operate database data directly in c.
It is simple, and the reusability is not high. Just write the Action directly.
If the reusability is high, you can write it into the Model.
Many people in Thinkphp think thatMActually extractedM()In this method.
The ing between the join fields in the Model and the database fields is more relevant to the meaning of the Model.
The layer of Thinkphp is not obvious. It's better than tangle. If it says something, you will know what code is to be extracted into the Model.
Search service layer pattern, entity + repository + service