Develop with MVC mode in PHP

Source: Internet
Author: User
Use the MVC mode in PHP for development 1. three phases in the software structure development process: Model1 mode & nbsp;, & nbsp; Model2 mode & nbsp;, & nbsp; the most important feature of MVC mode 1 & gt; Model1 is that there is no hierarchical concept & nbsp;, & nbsp; that is to say, processing the interface and business logic is completed in one file. disadvantages: & use MVC mode for development in PHP

1. three phases of software structure development:

Model1, Model2, and MVC

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

And business logic processing in a file to complete.

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

2 in the actual development process, it is not conducive to collaborative development by many people.

3 is not conducive to later maintenance

Advantages: 1. simple and fast development

2. suitable for small projects

2> Model2 layered mode: write the interface and business logic separately. the advantage is that the structure is clear and beneficial

Division of Labor Development. some books refer to this hierarchical mode as the MV mode,

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

In development, how do I change the program in Model1 mode to Model2:

1. PHP is used at the interface layer, and business logic classes (business operations are encapsulated in classes)

2. encapsulate common code (such as database operations) into classes.

3> MVC mode: the controller is added in the layered mode.

It forcibly separates application input, processing, and output. MVC applications are divided

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

M is mainly used by classes to process specific business logic.

V is mainly used as the interface to display data.

C is used to respond to various user requests.


2. why MVC:

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

It also processes various requests (such as deleting a piece of data on the current interface), but as the project continues to expand, there will be a lot of requests on the interface, if all are written in

The code is messy. that is to say, it is not good to directly send a request to the interface layer for processing, so the MVC mode is generated.



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.