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(); }
2.MODEL model:
Location D:wwwaoliHomeLibModelIndexModel.class.php
The code is as follows:
<?php class TestModel extends Model{ //对应数据库中的表test //可在此处添加操作数据库表的类 } ?>
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>
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.
There are many available for download on the official website. www.thinkphp.cn/case/index.html
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