: This article mainly introduces a simple MVC model. if you are interested in the PHP Tutorial, refer to it. MVC is a software method used to separate the logic layer and presentation layer of an application. In practice, because of this separation, your page contains only a few PHP scripts.
The model represents your data structure. Generally, model classes include methods to help you add, delete, modify, and query databases.
A view is the information to be presented to users. A view is usually a web page.
A controller is an intermediary between a model, a view, and any other resources necessary to process an HTTP request and generate a webpage.
Make a simple MVC model.
1. index. php
The only script file directly requested by the browser
2. controller
Coordinate models and views
3. model
Provide data and save data
4. view
Responsible for displaying webpages
5. action
Method in the controller, used for browser requests
------------------ Folder structure -------------------------
Master folder mvc_demo
-- Controllers
-- ArticleController. php
--UserControlLer. php
-- Models
-- UserModel. php
-- Views
-- User/index. php
Index. php // entry file
-----------------------------------------------------------
Index. php
$ ();
Controllers/
UserControlLer. php
UserControlLer {public function index () {// echo "this is the index method of the User controller"; // contains the file and instantiate a model include '. /models/UserModel. php '; // get data through the model $ model = new UserModel (); $ str = $ model-> getUser (); include '. /views/User/index. php ';}}
Models/UserModel. php
Views/User/index. php
In the browser, enter http: // localhost: 8080/mvc_demo/index. php? C = User & a = index, which shows the effect User helen.
The above introduces a simple MVC model, including the UserControl content, and hopes to help friends who are interested in PHP tutorials.