ThinkPHP (3.x/5.x/6.x) 默認訪問 `https://domain/` 時執行哪個模塊/控制器/方法?如何修改默認入口?
| 版本 | 默認模塊 | 默認控制器 | 默認方法 | 修改配置鍵 |
|---|---|---|---|---|
| TP 3.2 | Home | Index | index | `DEFAULT_MODULE`、`DEFAULT_CONTROLLER`、`DEFAULT_ACTION` |
| TP 5.0/5.1 | index (應用目錄) | Index | index | `app_route` 配置、`default_return_type`、路由完整定義 |
| TP 6.0/8.0 | index (應用目錄) | Index | index | `app.default_app`、`route.default_module`、`route.default_controller`、`route.default_action` |
return array(
'DEFAULT_MODULE' => 'Home', // 默認模塊
'DEFAULT_CONTROLLER' => 'Index', // 默認控制器
'DEFAULT_ACTION' => 'index', // 默認操作方法
// 路由開啟
'URL_ROUTER_ON' => true,
'URL_ROUTE_RULES' => array(
'/' => 'Home/Index/index', // 根路徑顯式映射
),
);
return [
'default_app' => 'index', // 默認應用 (單應用模式可忽略)
'app_namespace' => 'app',
// 路由配置 (route.php 更推薦)
'route' => [
'default_module' => 'index',
'default_controller' => 'Index',
'default_action' => 'index',
],
];
// TP 5.1/6.0/8.0
use think\Route;
Route::get('/', 'index/Index/index'); // 根路徑
Route::get('hello/:name', 'index/Index/hello'); // 動態參數
Route::post('api/user', 'api/User/save'); // API 分組
Route::group('admin', function () {
Route::get('user/list', 'admin/User/list');
})->middleware('auth'); // 中間件