簡單理解PHP.MVC之HelloWorld

來源:互聯網
上載者:User

標籤:

MVC即Model(模型)View(視圖)Controller(控制器)三者協同工作:1.瀏覽者->調用控制器,對他發出指令。2.控制器->按照指令選取合適的模型。3.模型->按照指令提取相應的資料(資料庫操作等)。4.控制器->按照相應的指令提取相應的視圖。5.視圖->將模型返回來的資料顯示到頁面(終端輸出)。 下面貼上相應的代碼
 1 testModel.class.php(模型) 2 <?php 3     class testModel{ 4         function getData(){ 5             return ‘hello world‘; 6         } 7     } 8 ?> 9 10 testView.class.php(視圖)11 <?php12     class testView{13         function display($data){14             echo $data;15         }16     }17 ?>18 19 testController.class.php(控制器)20 <?php21     class testController{22         function show(){23             $testModel = new testModel();24             $data = $testModel->getData();25             $testView = new testView();26             $testView->display($data);27         }28     }29 ?>30  31 協同工作32 testMVC.php33 <?php34     require_once(‘testController.class.php‘);35     require_once(‘testModel.class.php‘);36     require_once(‘testView.class.php‘);37     $controller = new testController();38     $controller->show();39 ?>

 

 

簡單理解PHP.MVC之HelloWorld

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.