thinkphp5 單入口多個模塊綁定和路由開關
index.php
入口代碼如下:
// 定義應用目錄
define('APP_PATH', __DIR__ . '/../app/');
require __DIR__ . '/../thinkphp/base.php';// 加載框架基礎文件
//開啟域名部署后
switch ($_SERVER['HTTP_HOST']) {
case 'www.xxxx.com':
$model = 'home';// home模塊
$route = true;// 開啟路由
break;
case 'admin.xxxx.com':
$model = 'admin';// admin模塊
$route = false;// 關閉路由
break;
}
\think\Route::bind($model ?? 'home');// 綁定當前入口文件到模塊
\think\App::route($route ?? true);// 路由
\think\App::run()->send();// 執行應用
