Home  >  Article  >  Backend Development  >  Understanding of MVC framework

Understanding of MVC framework

藏色散人
藏色散人Original
2019-04-16 13:48:493103browse

In the early days of software development, applications were complex wholes where logic and UI were inevitably entangled. In the late 1970s, the designers of the Smalltalk programming language developed a different approach to building applications - one that separated the "business" logic of the software from the elements that delivered an interface to the user and accepted their instructions.

The principles of software architecture—MVC, or Model-View-Controller—later became the design pattern for the vast majority of web applications and the frameworks on which they are based. PHP frameworks such as CodeIgniter, CakePHP and Laravel are designed to make building MVC style applications as easy as possible. Related recommendations: "mvc Design Pattern"

What is MVC?The best way to understand MVC is to understand the way it separates concerns in the application architecture .

Model

The model is the core of the MVC application. It is where the main logic and data objects that make up the core functionality of the application are developed. You can think of a model as a representation of the real-world knowledge that the application stores, processes, and delivers to the end user (although the details of delivery happen elsewhere).

The model is responsible for getting data from the database, packaging it into data objects that other components can understand, and delivering those objects - most of which will respond to input from the controller.

Controller (Controller)

The controller is the way the user interacts with the application. Typically, a controller receives a user request from an interface (usually in the form of an HTTP request from a web application) and calls a model, which retrieves and processes the data, before returning the data to the controller. The controller will then display these results to the user using the appropriate view.

View (View)

The view is where the data provided by the model is presented to the user. A view monitors visual (or other) interface elements—it selects, filters, and arranges the information provided by the model.

Different views can display information in different ways - one obvious implementation of multiple views is to handle the display of information on a mobile or desktop browser.

Please keep in mind that there are many different ways to implement an MVC architecture and the above is a high-level overview of the basic principles and does not reflect any specific implementation.

Why use MVC?

Developers use MVC architecture for the same reason that web designers use HTML (model) and CSS (view) instead of mixing By bringing structure, data and layout together, separating presentation and data reduces complexity and allows developers, for example, to build new front-end interfaces without changing the core logic. MVC reduces the complexity of web applications, making them easier to maintain.

Why use a framework?

MVC Framework Completes most of the basic framework work for building MVC applications. Developers simply extend the structures provided by the framework.

As you can imagine, building an MVC application from scratch is complex - frameworks make it easier to get started. Developers can focus on building the main logic of the application and which interfaces users will interact with that logic, rather than worrying about the complex business of organizing the components and how they will interact.

The above is the detailed content of Understanding of MVC framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn