An example of thinkphp's MVC development Mechanism _php Example

Source: Internet
Author: User

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.

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.