Home > Backend Development > PHP Tutorial > Example analysis of ThinkPHP's MVC development mechanism, thinkphpmvc_PHP tutorial

Example analysis of ThinkPHP's MVC development mechanism, thinkphpmvc_PHP tutorial

WBOY
Release: 2016-07-13 10:20:17
Original
1565 people have browsed it

Example analysis of ThinkPHP’s MVC development mechanism, thinkphpmvc

ThinkPHP is an MVC development framework that is currently widely used in China. This article analyzes ThinkPHP's MVC development mechanism in the form of examples. I believe it will be of some inspiration to everyone. The specific analysis is as follows:

1. Overview:

The MVC framework is analyzed as follows:

M Model layer Model : It is the database operation class (operate each table through the database operation class)
                             
V View layer View: refers to the template.
       
C Control layer controller: is to realize the control relationship between templates and models through the controller.

2. Example analysis:

1.ACTION controller:

Location D:wwwaoliHomeLibActionIndexAction.class.php

The code is as follows:

  public function test() //访问路径:http://localhost/aoli/index.php/Index/test
  {
    $Test=D('Test');//实例化Model
    //$list=$Test->select();
    $list=$Test->query("select * from test" );
    $this->assign('list',$list);
    $this->assign('title','彭艳杰');
    $this->display();
  }
  public function index() //index对应aoli\Tpl\default\Index下的index.html
  {
    $this->display();
  }

Copy after login

2.MODEL model:

Location D:wwwaoliHomeLibModelIndexModel.class.php

The code is as follows:

<&#63;php
class TestModel extends Model{ //对应数据库中的表test
 //可在此处添加操作数据库表的类
}
&#63;>

Copy after login

3.VIEW View:

Location D:wwwaoliHomeTpldefaultIndextest.html

The code is as follows:

 <p style=" font-weight:bold; line-height:22px;">{$title}</p>
 <div style=" color:#00F;">
  <volist name="list" id="vo">
   <p>{$vo.title} - {$vo.con}</p>
  </volist>
 </div>

Copy after login

Interested friends can debug and run the examples described in this article to deepen their understanding. I hope this article will help you learn ThinkPHP.

Think of a few examples and source code of thinkphp development. I am a newbie

There are many available for download on the official website. www.thinkphp.cn/case/index.html

Briefly discuss the understanding of the MVC pattern and briefly describe how the MVC pattern in ThinkPHP operates

MVC (Model-View-Controller) application structure is used to analyze the characteristics of distributed applications. This abstract structure can help divide the application into logical components, making program design easier.
The MVC structure provides a way to segment various objects by function (these objects are used to maintain and represent data), with the purpose of minimizing the degree of coupling between objects. The MVC structure was originally designed to apply traditional input, processing, and output tasks to the graphical user interaction model. However, it is also appropriate to apply these concepts to Web-based enterprise-level multi-tier applications.
In the MVC structure, the model represents the application's data and the business rules that control access and modification of this data. Typically a model is used as a software approximation of a process in the real world. When defining a model, common simple modeling techniques can be used.
When the model changes, it notifies the view (View) and provides the view with the ability to query the related state of the model. At the same time, it also provides the controller with the ability to access application functions encapsulated inside the model.
A View is used to organize the content of the model. It takes data from the model and specifies how that data should behave. When the model changes, the view is responsible for maintaining the consistency of data representation. At the same time, the user's requirements are notified to the controller (Controller).
The controller defines the behavior of the application; it is responsible for interpreting user requirements from the view and mapping these requirements into corresponding behaviors, which are implemented by the model. In a stand-alone GUI client, user requirements may be some mouse clicks or menu selection operations. In a web application, they might take the form of a number of GET or POST HTTP requests from the client. The behaviors implemented by the model include processing business and modifying the state of the model. Based on the user request and the results of the model behavior, the controller selects a view as a response to the user request. Usually a set of related functions corresponds to a controller. The following figure describes the relationship between the model, view and controller in an MVC application:
java has STRUCTS, SPRING
Reference: zhidao.baidu.com/question/304103632.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/868226.htmlTechArticleExample analysis of ThinkPHP’s MVC development mechanism, thinkphpmvc ThinkPHP is an MVC development framework that is currently widely used in China. This article analyzes ThinkPHP's MVC development mechanism in the form of examples. Phase...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template