PHP implementation of the simplest MVC Framework Example tutorial, MVC Framework Example Tutorial _php tutorial

Source: Internet
Author: User
Tags learn php learn php programming

PHP implementation of the simplest MVC Framework Example tutorial, MVC framework Example Tutorial


In this paper, the process of implementing the MVC framework in PHP is described in the form of an example, which is relatively easy to understand. We are now sharing it for your reference. The specific analysis is as follows:

First of all, before learning a framework, basically we all need to know what is MVC, that is, Model-view-control, is the data control and the separation of the page implementation, MVC is born, MVC is divided into three levels, and three levels of their respective, non-interference, First of all, a simple introduction, the various levels: view is views, that is, the Web page, control is the controller to the system issued instructions, the model is simply to remove data from the database for processing.

The MVC workflow is as follows:

1. Caller---Call the controller to issue instructions

2. Select a suitable model according to the instructions of the Controller

3. Select the corresponding data according to the controller instruction

4. Select the appropriate view by command

5. view, take the third step to the data as the user wants to show

A simple example is developed as follows, first to develop the first controller we have in this naming specification as follows testController.class.php

<?phpclass testcontroller{function Show () {}}?>

Second, write a simple model as follows testModel.class.php

<?php class Testmodel{function get () {return "Hello World";}}? >

The first view file is created testView.class.php to present the data

<?phpclass testvies{  function display ($data) {     echo $data;   }}? >

The next thing we do is to follow the previous five steps to test the program: the code follows the establishment of test files test.php

<?phprequire_once (' testController.class.php '); require_once (' testModel.class.php '); Require_once (' TestView.class.php '); $testController = new TestController ();//Call Controller $testcontroller->show ();? >

<?phpclass testcontroller{  function Show () {      $testModel = new Testmodel ();//Select the appropriate model      $data = $testModel- >get ();//get the corresponding data      $testView = new TestView ();//Select the appropriate view      $testView->display ($data);//show the user  }}?>

Then our browser opens test.php will be displayed as Hello World, indicating that we have succeeded.

Note: This example is only for frame structure, and the specific function reader can add it yourself. It is hoped that the examples mentioned in this article will help us to learn PHP programming framework.


The simplest example of PHP MVC

Framework is the design pattern of the present
Design pattern is a way of thinking about problem solving

What you should do now is to think back and think about what problems you have encountered during this year's PHP learning, the problems that should be addressed at the technical level, and those that require you to reconsider your own procedural thinking before you think about the framework will be better.
Smarty is just a template, but after you understand the framework, you do not have to use cakephp or anything, you can directly use Smarty as part of your own framework, even you can even smarty do not need to write a more appropriate template library to use is also very good.
--------------------------
The key problem is, you have to understand why the framework, do not look at others are saying that the framework is good, you do not know where the framework, you are not learning framework.
So, you should be warm now, then you can know the new.


PHP's MVC framework for a super simple fool-like Hello World demo

Framework is the design pattern of the present
Design pattern is a way of thinking about problem solving

What you should do now is to think back and think about what problems you have encountered during this year's PHP learning, the problems that should be addressed at the technical level, and those that require you to reconsider your own procedural thinking before you think about the framework will be better.
Smarty is just a template, but after you understand the framework, you do not have to use cakephp or anything, you can directly use Smarty as part of your own framework, even you can even smarty do not need to write a more appropriate template library to use is also very good.
--------------------------
The key problem is, you have to understand why the framework, do not look at others are saying that the framework is good, you do not know where the framework, you are not learning framework.
So, you should be warm now, then you can know the new.

http://www.bkjia.com/PHPjc/875873.html www.bkjia.com true http://www.bkjia.com/PHPjc/875873.html techarticle PHP Implementation of the simplest example of the MVC framework, MVC Framework Example Tutorial This article is an example of the implementation of the MVC framework of PHP process, relatively easy to understand. Now share for everyone ...

  • 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.