A simple MVC model

Source: Internet
Author: User
: 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.

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.