Home > PHP Framework > ThinkPHP > body text

What is the difference between thinkphp controller and model

爱喝马黛茶的安东尼
Release: 2019-08-26 13:09:03
Original
4969 people have browsed it

What is the difference between thinkphp controller and model

MVC is a design pattern that enforces separation of input, processing, and output of an application. Applications using MVC are divided into three core components: model (M), view (V), and controller (C), each of which handles its own tasks.

Related recommendations: "ThinkPHP Tutorial"

View: View is the interface that users see and interact with. For old-style Web applications, the view is an interface composed of HTML elements. In new-style Web applications
, HTML still plays an important role in the view, but some new technologies have emerged in endlessly, including Adobe
Flash and some markup languages ​​and Web services like XHTML, XML/XSL, WML, etc. How to deal with an application's interface is becoming more and more challenging. One of the big benefits of MVC is that it can handle many different views for your application. No real processing occurs in the view, whether the data is stored online or a list of employees. As a view, it just serves as a way to output the data and allow the user to manipulate it.

Model: Model represents enterprise data and business rules. Among the three components of MVC, the model has the most processing tasks. For example, it might use component objects like EJBs and ColdFusion
Components to handle databases. The data returned by the model is neutral, which means that the model has nothing to do with the data format, so that a model can provide data for multiple views. Code duplication is reduced because the code applied to the model only needs to be written once and can be reused by multiple views.

Controller: The controller accepts user input and calls models and views to complete the user's needs. So when a hyperlink in a Web page is clicked and an HTML form is sent, the controller itself does not output anything or do any processing. It just receives the request and decides which model component to call to handle the request, and then determines which view to use to display the data returned by the model processing.

Now we summarize the MVC processing process. First, the controller receives the user's request and decides which model should be called for processing. Then the model uses business logic to process the user's request and return the data. Finally, the controller uses the corresponding The view formats the data returned by the model and presents it to the user through the presentation layer.

The above is the detailed content of What is the difference between thinkphp controller and model. For more information, please follow other related articles on the PHP Chinese website!

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