Php的MVC單點通道口

來源:互聯網
上載者:User
Php的MVC單點入口

Php的MVC單點入口

?

/index.php

/**

* MVC示範demo

* 僅僅實現最基本的MVC功能,不包含安全處理,資料過濾,及其他最佳化措施。

*/

define(‘SITE_PATH’,str_replace(”,’/',dirname(__FILE__)));//定義系統目錄

$controller=(!empty($_GET['controller']))?$_GET['controller']:’index’;//擷取控制器,預設index

$action=(!empty($_GET['action']))?$_GET['action']:’index’;//方法名稱,預設index

$controller_name=$controller.’Controller’;

$controller_file=SITE_PATH.’/app/controller/’.$controller_name.’.class.php’;//擷取控制器檔案

if(file_exists($controller_file)){

require_once($controller_file);

$controller=new $controller_name();

$controller->{$action.’Action’}();

}else{

die(‘找不到對應的控制器!’);

}

?>

?

對應的一個示範demo

/app/controller/testController.class.php(注意路徑)

/**

* MVC示範demo

* 僅僅實現最基本的MVC功能,不包含安全處理,資料過濾,及其他最佳化措施。

*/

class testController

{

function testAction(){

echo ‘Hello,World!’;

}

}

?>

開啟瀏覽器,輸入http://path/to/yoursite/index.php?controller=test&action=test(注意相應的修改你的路徑),如果你看到Hello,World!說明MVC第一步,單點入口成功了!

  • 聯繫我們

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