Home  >  Article  >  Backend Development  >  Developing using the MVC pattern in PHP_PHP Tutorial

Developing using the MVC pattern in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:51919browse

1. Three stages in the development process of software structure:

 Model1 mode, Model2 mode, MVC mode

1>The most important feature of Model1 is that there is no concept of layering, which means that the interface

Put the business logic processing in one file.

Disadvantages: 1. The presentation layer and business logic layer are mixed together, which is very messy

 2 In the actual development process, it is not conducive to collaborative development by multiple people.

 3 Not conducive to later maintenance

Advantages: 1. Simple, faster development

 2 More suitable for developing small projects

 2>Model2 layered mode: writing the interface and business logic separately, the advantage is that the structure is clear, which is conducive to

Division of labor development. Some books call this layered model the MV model,

That is, M-->Model (business logic layer), V-->View (interface layer)

How to change the Model1 mode program to Model2 during development:

 1, the interface layer uses PHP, and the business logic uses classes (business operations are encapsulated in classes)

 2. Encapsulate commonly used codes (such as database operations, etc.) into classes.

 3>MVC mode: In fact, a controller is added in layered mode.

It forces the input, processing and output of the application to be separated. Using MVC the application is divided into

Three core components: Model M, View V, Controller C

M is mainly made of classes, which are used to handle specific business logic.

V is mainly used as an interface to display data.

 C is used to respond to various requests from users.

 2. Why use MVC:

We found that in Model2 mode, the interface not only serves as a display function,

It also handles various requests (such as deleting a certain piece of data on the current interface). However, as the project continues to expand, there will be many requests on the interface. If they are all written on the interface,

The code will look very messy. In other words, it is not very good to hand a certain request directly to the interface layer for processing, so the MVC model came into being.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371936.htmlTechArticle1, 3 stages in the development process of software structure: Model1 mode, Model2 mode, MVC mode 1Model1 is the most important The characteristic is that there is no concept of layering, which means that the interface and business logic...
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