Php implementation of the simplest MVC framework instance tutorial, mvc framework instance tutorial _ PHP Tutorial

Source: Internet
Author: User
Php implements the simplest MVC framework instance tutorial and mvc framework instance tutorial. Php implements the simplest MVC framework instance tutorial. mvc framework instance tutorial this article describes the process of PHP implementing MVC framework in the form of an instance, which is easy to understand. I will share with you the simplest MVC framework example tutorial and mvc framework example tutorial for php implementation.

This article describes how PHP implements the MVC framework in the form of an example, which is easy to understand. I would like to share it with you for your reference. The specific analysis is as follows:

First, before learning a framework, we basically need to know what mvc is, that is, model-view-control. to put it simply, data control and page separation are implemented, mvc came into being in this way. mvc is divided into three layers, and each layer performs its own duties and does not interfere with each other. First, let's briefly introduce each layer: view is view, that is, web page, control is a tool used by the controller to send commands to the system. The model simply refers to extracting data from the database for processing.

The MVC workflow is as follows:

1. viewer-> call the controller to issue the command

2. Controller-> select an appropriate model by command

3. model-> select the corresponding data according to the controller command

4. Controller-> select the view according to the command

5. View-> display the data obtained in step 3 as you want.

Simple instance development is as follows. First, we will develop the first controller. the naming rules here are as follows: testController. class. php

<?phpclass testController{function show(){ }}?>

Next, write a simple model: testModel. class. php

<?php class testModel{function get(){return "hello world"; }}?>

TestView. class. php is created for the first view file to present the data

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

Next we need to test the program according to the five steps mentioned above: the code is as follows: test. php is created in the test file.

<? Phprequire_once ('testcontroller. class. php '); require_once ('testmodel. class. php '); require_once ('testview. class. php '); $ testController = new testController (); // call the controller $ testController-> show ();?>

<? Phpclass testController {function show () {$ testModel = new testModel (); // select an appropriate model $ data = $ testModel-> get (); // obtain the corresponding data $ testView = new testView (); // select the corresponding view $ testView-> display ($ data); // display it to the user}?>

Then we open test. php in the browser and it will be displayed as hello world, indicating that we have succeeded.

Note: the examples in this article are only framework structures. you can add specific functions on your own. I hope the examples described in this article will help you learn the PHP programming framework.


The simplest example of php mvc

The framework is the current design model
Design pattern is the way to solve the problem

What you should do now is to look back and think about what problems you have encountered in your PHP learning over the past year, which should be solved at the technical level, those problems can be solved only after you rethink about your program ideas, and then consider the framework.
Smarty is just a template, but after you understand the framework, you don't have to use cakephp or anything. you can directly use smarty as part of your own framework, even if you don't need smarty, you can write a more suitable template library by yourself.
--------------------------
The key issue is that you need to understand why the framework is required. don't look at what others say that the framework is good. you don't know where the framework is. you cannot learn the framework well.
Therefore, you should give it a warm-up now, and then let us know new things.

 

The MVC framework of PHP requires a simple and silly hello world demonstration.

The framework is the current design model
Design pattern is the way to solve the problem

What you should do now is to look back and think about what problems you have encountered in your PHP learning over the past year, which should be solved at the technical level, those problems can be solved only after you rethink about your program ideas, and then consider the framework.
Smarty is just a template, but after you understand the framework, you don't have to use cakephp or anything. you can directly use smarty as part of your own framework, even if you don't need smarty, you can write a more suitable template library by yourself.
--------------------------
The key issue is that you need to understand why the framework is required. don't look at what others say that the framework is good. you don't know where the framework is. you cannot learn the framework well.
Therefore, you should give it a warm-up now, and then let us know new things.

This article describes how PHP implements the MVC framework in the form of an example, which is easy to understand. I will share it with you...

Related Article

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.