Home > Backend Development > PHP Tutorial > A brief explanation of using PHP to implement MVC_PHP tutorial

A brief explanation of using PHP to implement MVC_PHP tutorial

WBOY
Release: 2016-07-21 14:56:03
Original
746 people have browsed it

The traditional procedural development method begins to show its insufficiency when dealing with medium-sized and above applications. Even if we can complete the requirements quickly, after the requirements change or when performing post-maintenance, we will fall deeply into the trap we built early. Therefore, using an object-oriented approach to implement the MVC pattern will provide us with a clear idea for sorting out the program's architecture.

What is MVC?

There are many definitions and explanations of MVC. We can find a more detailed explanation in Wiki or [2]. I do not intend or have the ability to explain it in depth here. From the perspective of PHP development, MVC can be summarized as:

View (The View):

When it comes to views, many of us think of template engines (such as Smarty, etc.). In fact, it is a variety of outputs, such as html templates and Javascript files.

Module (The Model)

Module represents the logic of the program and is usually called the business logic layer in enterprise applications. Generally speaking, the work done by this layer is to process the original data into meaningful data sequences stored according to the data structure we designed, and hand these data to the view for processing. Normally, a data abstract class is used in the module to perform processing related to data operations.
Model usually contains functions used to deal with the database.

The Controller

The Controller is the first stop for all WEB applications. It accepts received parameters, such as the $_GET variable, and then responds accordingly.

There are also many debates about whether MVC is suitable for PHP. People continue to discuss whether MVC is suitable for PHP[3]. Now there are many MVC frameworks, such as those listed in PHP MVC Frameworks[4] . So, why are people so keen on MVC, and why should we use MVC in our designs.

Why use MVC?

MVC was first used to solve desktop GUI programming problems. The earliest MVC framework should be Model 2 proposed by Sun in 1999, which later evolved into Struts. MVC gives people a deep impression, but when we use it, we don't seriously think about why we use MVC.
In traditional desktop applications, once something happens in the Model, we can actively refresh the View interface to show the changes that have occurred in the background. In web applications, we seem to be limited to the traditional Http Request/Response method, and we seem to have no way to let the client update. This discussion does not mean that MVC cannot be used to develop WEB applications, but that to some extent, it is not the most suitable.
There are still many debates about using MVC[1], but I believe that all people who are accustomed to using MVC to organize their own projects will definitely not give up MVC when asked to choose a new project architecture.

  • Total 2 pages:
  • Previous page
  • 1
  • 2
  • Next page

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364295.htmlTechArticleThe traditional face-to-face procedural development method begins to seem inadequate when dealing with medium-sized or larger applications. Even if we can complete the requirements quickly, after the requirements change or...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template