Thinkphp is an MVC development framework which is widely used in China at present. In this paper, we analyze the MVC development mechanism of thinkphp with the example form. I believe that it will give you a certain enlightening effect. The specific analysis is as follows:
First, overview:
The MVC framework resolves as follows:
M model Layer Models : is the database Operation class (through the database operation class to manipulate the tables)
V View Layer view: refers to the template.
C Control Layer Controller: It is through the controller to achieve the template, the relationship between the model.
Second, the case analysis:
1.ACTION Controller:
Location D:\www\aoli\Home\Lib\Action\IndexAction.class.php
The code is as follows:
Public function test ()//access path: Http://localhost/aoli/index.php/Index/test
{
$Test =d (' test ');//Instantiate model
//$list = $Test->select ();
$list = $Test->query ("SELECT * from Test");
$this->assign (' list ', $list);
$this->assign (' title ', ' Peng Yanjie ');
$this->display ();
}
The Public Function index ()//index corresponds to the index.html
{
$this->display () under Aoli\tpl\default\index;
}
2.MODEL Model:
Location D:\www\aoli\Home\Lib\Model\IndexModel.class.php
The code is as follows:
<?php class
Testmodel extends model{//tables in the corresponding database test
//You can add the classes for manipulating database tables
here
?>
3.VIEW View:
Location D:\www\aoli\Home\Tpl\default\Index\test.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 through the examples described in this article to deepen understanding. I hope this article will help you learn thinkphp.