PHP MVC pattern (1)-MVC architecture

Source: Internet
Author: User

PHP Advanced Programming Learning Note 2014.06.18

MVC (Model-view-controller, model-View-controller) is a very common design pattern that simplifies application development and maintenance. It logically separates the application into pieces. The model part is responsible for the business logic of the application, encapsulating the methods that access the database and providing a reusable class library. The view section controls the appearance of the data and provides a mechanism for collecting data from users. The controller section, which is responsible for connecting all matters, collects data from the view and determines the execution logic of the program. Invokes the mechanism of the model and parses the returned data, then submits the data to the view for presentation to the customer. Choose the right framework to consider five shutdown factors: architecture, documentation, community, support, and flexibility.

A typical workflow based on MVC

The designer makes a static, individual prototyping based on existing business needs and the functions that the application asks for. The developer is then reviewed. The developer is responsible for ensuring that all required functions are militarily viable, and if the developer does not find any problems, they create a development plan that includes the API model, which is then referred to the integrator (the controller layer). If there is a problem with the prototype, the project goes back to the designer and continues the process in front of the loop.

Once the prototype API model is ready, the integration work begins. The integrator will study the prototype design and convert it into a template language and integrate the design into the site URL structure. Then write the controller that will distribute the request between the Web server and the model information that they need to manipulate. After the result is generated, the view is fetched and output, and the controller provides values for all dynamic content.

Finally, once the API model is fully implemented, you can give the application to the tester. If the model developer strictly adheres to the API code, and the integrator writes the controller according to the specification, the test work will proceed smoothly.

MVC Application

Application portals, an MVC site typically implements a core script that is used to process requests on a Web site. This file is referred to as the boot file. The bootstrap file is responsible for initializing the framework, including the automatic loading of classes, reading the configuration, parsing URLs into the model, populating the request information, initializing the controller program, and so on.

After the boot is complete, the front controller is instantiated and takes over the program's operation. The front-end controller class is the built-in class that interprets the request variable, which routes the client request to a method on the action controller, which is called an action, and the action is responsible for all functions. This method will instantiate the model class, parse the view template, and output the results.

Models generally do not follow any particular structure, but exist with a common location, all of which may be automatically loaded by the framework. A model is a tool class that provides the required data manipulation and parsing capabilities.

Views are templates that can be written in any template language. The purpose of the view is not to include any type of processing logic or data manipulation in the view, and to output only the data provided by the Controller. The choice of template language (for example: Fasttemplate/smarty) depends on the integration with the target framework.

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.