欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

初識php MVC

 更新時間:2014年09月10日 10:01:42   投稿:hebedich  
MVC全名是Model View Controller,是模型(model)-視圖(view)-控制器(controller)的縮寫,一種軟件設(shè)計典范,用一種業(yè)務(wù)邏輯、數(shù)據(jù)、界面顯示分離的方法組織代碼,將業(yè)務(wù)邏輯聚集到一個部件里面,在改進和個性化定制界面及用戶交互的同時,不需要重新編寫業(yè)務(wù)邏輯。

學(xué)習(xí)一個框架之前,基本上我們都需要知道什么是mvc,即model-view-control,說白了就是數(shù)據(jù)控制以及頁面的分離實現(xiàn),mvc就是這樣應(yīng)運而生的,mvc分為了三個層次,而且三個層次各司其職,互不干擾,首先簡單介紹下,各個層次,view即是視圖,也就是web頁面,control即是控制器 向系統(tǒng)發(fā)出指令的工具,model 簡單說是從數(shù)據(jù)庫中取出數(shù)據(jù)進行處理。

Mvc的工作流程:第一步 瀏覽者->調(diào)用控制器,對此發(fā)出指令

                    第二步 控制器->按指令選取一個合適的模型

                     第三步 模型->按照控制器指令選取相應(yīng)的數(shù)據(jù)

                     第四步 控制器->按指令選取相應(yīng)的視圖

                    第五步 視圖->把第三步取到的數(shù)據(jù)按用戶想要的樣子顯示出來

簡單地實例開發(fā)如下,首先進行第一個控制器的開發(fā) 我們在此命名規(guī)范如下testController.class.php

<?php
 
 class testController{
 
function show(){
 
}
 
 }
 
?>

         其次書寫一個簡單地模型如下testModel.class.php

<?php
 
class testModel{
 
function get(){
 
return "hello world";
 
}
 
}
 
?>

  
         第一個視圖文件的創(chuàng)建testView.class.php 是為了呈現(xiàn)數(shù)據(jù)所存在的

<?php
class testVies{
 
  function display($data){
 
     echo $data;
 
  }
 
 }
 
?>  

   

         下面我們要做的就是按照之前所說的五步進行程序的測試:代碼如下 測試文件的建立test.php

<?php
 
require_once('testController.class.php');
 
require_once('testModel.class.php');
 
require_once('testView.class.php');
 
$testController = new testController();//調(diào)用控制器
 
$testController->show();
 
?>

 

<?php
 
class testController{
 
  function show(){
 
      $testModel = new testModel();//選取合適的模型
 
      $data = $testModel->get();//獲取相應(yīng)的數(shù)據(jù)
 
      $testView = new testView();//選擇相應(yīng)的視圖
 
      $testView->display($data);//展示給用戶
 
  }
 
}
 
?>

         而后我們?yōu)g覽器打開test.php 會顯示為hello world,說明我們已經(jīng)成功了。

相關(guān)文章

最新評論