In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the meaning of MVC layering in thinkphp5". In daily operation, I believe that many people have doubts about the meaning of MVC layering in thinkphp5. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "what is the meaning of MVC layering in thinkphp5?" Next, please follow the editor to study!
In thinkphp5, MVC layering refers to the division and cooperation of model layer, view layer and controller layer, and the separate operation of logic layer and presentation layer; the model layer is responsible for database operation, and the controller is a module class, which is scheduled and operated according to url, and the view is used to connect action controller and template files.
This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.
What is MVC layering in thinkphp5
MVC,M model, V view, C controller.
Layering is the division of work and cooperation, and the operation of the logic layer and the presentation layer are separated. The model is responsible for: database operation. Controller: any WEB operation is an operation of a module, and the controller is a module class that schedules and operates according to url. View (composed of view class and template file): connect the action controller and the template file, the Action class transfers the data to the template file through the View class, and the template file converts the received data into the corresponding data format display.
ThinkPHP is based on the MVC (Model-View-Controller, Model-View-Controller) pattern and supports multi-tier (multi-Layer) design.
Model (Model) layer
The default model layer is composed of Model classes, but with the growth of the project and the complexity of the business system, a single model layer is difficult to solve the requirements. The design idea of supporting multi-tier Model is very simple, and different model layers are still inherited from the system's Model classes, but a distinction is made between directory structure and naming conventions.
For example, in a project design, we need to distinguish different model layers such as data layer, logic layer, service layer and so on. We can create model, logic and service directories under the module directory to divide all model operations on the user table into three layers:
Data layer: model/User is used to define data-related automatic verification and autocompletion and data access interfaces
Logic layer: logic/User is used to define user-related business logic
Service layer: service/User is used to define user-related service interfaces, etc.
All three model operation classes inherit the\ think\ Model class.
The hierarchical division of the model layer is very flexible, developers are free to define and add model layering according to the needs of the project, or you can only use the Model layer.
View (View) layer
The view layer consists of a template and a template engine. PHP code can be used directly in the template. The design of the template engine will be described later, and other third-party template engines can also be supported by the driver. Multiple layers of a view can be simply distinguished by catalogs, such as:
View/default/user/add.htmlview/blue/user/add.html
A more complex multi-tier view can go a step further, using different view catalogs, such as:
View General View layer directory
Mobile mobile phone accesses the view layer directory
Controller (Controller) layer
The controller layer of ThinkPHP consists of a core controller and a service controller. The core controller is completed by the App class within the system, which is responsible for the scheduling and control of applications (including modules, controllers and operations), including HTTP request interception and forwarding, loading configuration and so on. The business controller is completed by a user-defined controller class. The implementation principle of the multi-tier service controller is similar to the layering of the model, such as the service controller and the event controller:
Controller/User / / for user's business logic control and scheduling event/User / / for user's event response operation
Controller\ User is responsible for external interactive responses, requesting responses through URL, such as http://serverName/User/index, while event\ User is responsible for internal event responses and can only be called internally, so it is isolated from the outside. The division of multi-layer controller is not mandatory, and it can be layered freely according to the needs of the application. In the controller hierarchy, you can call the hierarchical model as needed, or you can call different hierarchical views.
At this point, the study on "what is the meaning of MVC layering in thinkphp5" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 214
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.