ThinkPHP的MVC開發機制執行個體解析_php執行個體

來源:互聯網
上載者:User
ThinkPHP是目前國內應用非常廣泛的一款MVC開發架構。本文就以執行個體形式解析ThinkPHP的MVC開發機制。相信會給大家一定的啟發作用。具體分析如下:

一、概述:

MVC架構解析如下:

M Model層 模型:就是資料庫操作類(通過資料庫操作類去操作各個表)

V View層 視圖:指模版。

C Control層 控制器:就是通過控制器來實現模版,模型之間的控制關係。

二、執行個體分析:

1.ACTION 控制器:

位置 D:\www\aoli\Home\Lib\Action\IndexAction.class.php

代碼如下:

  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 模型:

位置 D:\www\aoli\Home\Lib\Model\IndexModel.class.php

代碼如下:

<?phpclass TestModel extends Model{ //對應資料庫中的表test //可在此處添加操作資料庫表的類}?>

3.VIEW 視圖:

位置 D:\www\aoli\Home\Tpl\default\Index\test.html

代碼如下:

 

{$title}

{$vo.title} - {$vo.con}

感興趣的朋友可以調試運行一下本文所述執行個體以加深理解。希望本文所述對於大家學習ThinkPHP有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.