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)05/31 Report--
This article mainly introduces how to use PHP to achieve a simple MVC framework related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone after reading this article on how to use PHP to achieve a simple MVC framework will have a harvest, let's take a look at it.
I. Preface
MVC, whose full name is Model View Controller, is a pattern for designing and creating web applications using model-view-controller, and is a design paradigm.
Where:
Model (model): the part of an application that deals with application data logic and is usually responsible for direct curd interaction with the database.
View (View): the part of the application that processes the display of data by rendering the processed data.
Controller (controller): the part of an application that handles user interaction and is usually used to handle the distribution of data logic and back to the view and controller accordingly.
Advantages:
Low coupling
High reusability
Fast deployment and low lifecycle cost
High maintainability
Disadvantages:
Increase the complexity of system structure and implementation
Overly tight connection between the view and the controller
2. Which frameworks use mvc architecture?
At present, mvc architecture has been used in the mainstream framework of php, such as:
ThinkPHP, Laravel and Yii all have the architecture of mvc.
III. Brief introduction of frame structure
Where:
App directory: used to store view controller models, etc.
Config directory: some common configuration files used to store the framework.
Core directory: used to store some base class files, such as controller base class, model base class, view base class, request request base class, db chain operation base class, etc.
Static directory: used to store some static resources, such as: pictures, html view files, js, cs files, etc.
Index.php: the entry file of the entire framework for distribution startup.
Fourth, the first step in the implementation of the framework (parsing routing)
Why is parsing routes the first step?
Only after successfully resolving the route, can you use MVC after accessing a method in a certain class, because parsing the route is also the most basic part of the framework implementation, and the automatic loading mechanism of PHP is necessary to resolve the route.
At present, the automatic loading mechanism of php can be divided into two mechanisms: composer automatic loading mechanism and manual automatic loading mechanism. the simple framework is completed by manual automatic loading mechanism.
4.1 write entry file
Index.php:
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: 0
*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.