MVC architecture – quick understanding in 5 minutes | #00003

What is MVC?

Simply put, MVC is the abbreviation of Model, View, Controller.

I only came into contact with MVC when I was a rookie out of the society, and it has been many years since now.

 

For this architecture, I used to search on GOOGLE to learn more about the meaning of this architecture, but unfortunately there are many examples and explanations on the Internet that are slightly more difficult, which makes it difficult for me to explain it to other colleagues who are studying together, and it is also difficult. I experienced the feeling of this MVC architecture through these articles, but at that time I still wrote a simple mental explanation. Looking back now, I still feel that it is too simple and the explanation is not clear enough.

 

In fact, at that time, I was also very grateful to Codeigniter for this set of PHP framework, because his quick start allowed me to fully understand what MVC is, instead of learning about MVC through other difficult and difficult articles on the Internet. For MVC In fact, it is just a mentality, a concept.

 

Taking the web page structure as an example, I think it may be the easiest to understand what is the concept of MVC.

content directory

view

The page (screen) in the browser we currently “see” is a V, and V means View or translated as View.

The display, arrangement, color, etc. of the things you see on the screen can be summarized in the so-called View. The technologies used in it may include html, css, javascript, jquery or more in-depth js frameworks, such as vue, react…etc., the full-time engineers in this part can also be called “front-end engineers”.

model

There are a lot of information on the webpage stored in the database, such as the price of the goods on the auction site, the content of your blog post, the title, the date of creation…etc.

When we want to take out these data, we need to use SQL syntax to take out the database. For example, how many books are left in the inventory of this book? Then the database grammar program we wrote can be written in the Model Inside, the so-called Model is to put the program code about the syntax of the database operation. There may be some simple judgment formulas in it, but basically the operation of the database content is the main thing.

Controller

What about C? What about the so-called Controller?

The so-called C actually refers to the logical calculation operation, translated into English as the controller, he has two main tasks.

The first task is logical judgment and calculation. The logic application of some of our web pages, for example, after entering the account password on the login page, sends the form data to the controller through the front-end html. The controller must first judge whether it conforms to the format of the set account password. , Whether the format is correct or not is judged by C. If the format of the input is correct, the Controller will use the Model to retrieve the account password that was originally set from the database to confirm whether your input is correct.

Smart people can guess from the above description that another task of C (the second task) is to connect View and Model. You can think of it as a strategic brain control center, which is in charge of the control from the front end to the database. Or, the so-called “back-end engineer” refers to a full-time engineer who works on C and M programs. In terms of web pages, related technologies include PHP, JAVA, .NET…etc.

Well, I have roughly explained what MVC is, then we can say, what is a “full-terminal engineer”. A full-terminal engineer refers to an engineer who is proficient in MVC technical grammar. Wu Ya, it is not easy to become a full-end engineer. Milk wine is only a back-end engineer at present, but I can’t finish learning what I want to learn.

 

Long-winded and put forward some points that should be paid attention to about MVC. There are two things that I am very insisting on.

1. The View should not directly access the Model, but must pass through C.

Second, C should not spit out (print out) the front-end syntax, such as: HTML, CSS syntax… etc., these must be controlled by the front-end.

 

For the above simple explanation, I will not tell you the code or write a program. I will try to use words and give examples to let everyone understand.

If you like my article or my article is helpful to you, please like or share it, thank you for watching

Leave a Comment

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com
Scroll to Top