Questions about the MVC framework

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.