mvc-Framework.class.php

來源:互聯網
上載者:User

標籤:frame   action   cti   rar   iss   add   roo   手動   .class   

<?php
//核心啟動類
class Framework{
//讓項目啟動起來
public static function run(){
//echo "running...";
self::init();
self::autoload();
self::router();
}

//初始化方法
public static function init(){
//定義路徑,擷取當前工作路徑 getcwd()
define("DS", DIRECTORY_SEPARATOR);
define("ROOT", getcwd() . DS); //項目根目錄
define("APP_PATH", ROOT . "application" . DS);
define("FRAMEWORK_PATH", ROOT . "framework" .DS);
define("PUBLIC_PATH", ROOT . "public" . DS);
define("MODEL_PATH", APP_PATH . "models" . DS);
define("VIEW_PATH", APP_PATH . "views" . DS);
define("CONTROLLER_PATH", APP_PATH . "controllers" .DS);
define("CONFIG_PATH", APP_PATH . "config" .DS);
define("CORE_PATH", FRAMEWORK_PATH . "core" .DS);
define("DB_PATH", FRAMEWORK_PATH . "database" . DS);
define("HELPER_PATH", FRAMEWORK_PATH . "helpers" . DS);
define("LIB_PATH", FRAMEWORK_PATH . "libraries" .DS);
//前背景控制器和視圖目錄怎麼定義呢?,解析url中的參數,可以確定具體的路徑
define("PLATFORM", isset($_REQUEST[‘p‘]) ? $_REQUEST[‘p‘] :"home");
define("CONTROLLER", isset($_REQUEST[‘c‘]) ? ucfirst($_REQUEST[‘c‘]) :"Index");
define("ACTION", isset($_REQUEST[‘a‘]) ? $_REQUEST[‘a‘] :"index");
define("CUR_CONTROLLER_PATH", CONTROLLER_PATH . PLATFORM . DS);
define("CUR_VIEW_PATH", VIEW_PATH . PLATFORM . DS);

define("UPLOAD_PATH", PUBLIC_PATH . "uploads" . DS);
//手動載入核心類
require CORE_PATH . "Controller.class.php";
require CORE_PATH . "Model.class.php";
require DB_PATH . "Mysql.class.php";
$GLOBALS[‘config‘] = include CONFIG_PATH . "config.php";

//開啟session
session_start();
}

//路由方法
public static function router(){
//確定類名和方法名
$controller_name = CONTROLLER . "Controller"; //如GoodsController
$action_name = ACTION . "Action"; //如addAction
//執行個體化控制器,然後調用相應的方法
$controller = new $controller_name;
$controller->$action_name();
}

//註冊載入方法
public static function autoload(){
spl_autoload_register(array(__CLASS__,"load"));
}

//載入方法
public static function load($classname){
//只負責載入 application下面的 控制器類和模型類,如GoodsController,AdminModel
if (substr($classname, -10) == ‘Controller‘){
require CUR_CONTROLLER_PATH . "{$classname}.class.php";
} elseif (substr($classname, -5) == "Model"){
require MODEL_PATH . "{$classname}.class.php";
} else {
//其它情況,暫無
}

}
}

mvc-Framework.class.php

聯繫我們

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