I am learning about the MVC framework. I know that V is a view, that is, an HTML template. C is the controller. enter the routing URL in the browser and then call the controller method. However, I have a question: whether the statements used to operate databases are stored in M or C. I think there are many examples on the internet. I also put database operations in C, which makes me a little confused, so what is the role of M? ------ Solution ------------------ M & nbsp; model & MVC framework problems
I am learning the MVC framework. I know that V is a view, that is, an HTML template. C is the controller. enter the routing URL in the browser and then call the controller method. However, I have a question: whether the statements used to operate databases are stored in M or C. I think there are many examples on the internet. I also put database operations in C, which makes me a little confused, so what is the role of M?
------ Solution --------------------
M model
It is used to reflect the business logic, that is, the operation on specific things.
Because web applications cannot be separated from databases, databases can best reflect the characteristics of projects.
Therefore, the operation on the database is usually used as M
------ Solution --------------------
MVC is just a general layered method, and it is not necessary to be so rigid.
M is a MODEL layer, and it is a number of classes. this can make every table in your database a MODEL.
V is the view layer. It can also be understood as HTML, but it is definitely not HTML. you can see what template engine is used in the view layer.
C is the control layer, that is, your boot file breaks down the URL and finds the corresponding controller and processing method, and then calls the class of M layer in the specific method. After processing, go to the specific view layer, fill in the data, and then send it to the user's browser.
The above is relatively simple.
When I do this, I divide the M layer into two layers (in fact, one layer), and the others remain unchanged.
I divide the M layer into a simple class layer and a service layer. For example, there is a people table in my database:
I write people into a class. this class only provides the get and set methods for table attributes.
Then there is a peopleService class, which provides people operations, mainly CRUD operations and some logical operations.