project/ ├── initphp/ # 框架核心 (git submodule 建議) ├── conf/ │ └── comm.conf.php # 專案配置 ├── web/ │ ├── controller/ # 控制器 │ └── index.php # 入口文件 └── runtime/ # 快取、日誌 (需寫入權限)
<?php
// web/index.php
define('APP_PATH', __DIR__ . '/../');
require APP_PATH . 'initphp/initphp.php';
// 載入專案配置
$configFile = APP_PATH . 'conf/comm.conf.php';
if (file_exists($configFile)) {
InitPHP::setConfig(include $configFile);
}
InitPHP::init();
<?php
// conf/comm.conf.php
return [
'url' => 'https://local.initphp.com/', // 專案域名
'controller' => [
'default_controller' => 'index', // 預設控制器
'default_action' => 'run', // 預設動作
'controller_suffix' => 'Controller', // 類別後綴
],
'db' => [
'default' => [
'host' => '127.0.0.1',
'user' => 'root',
'pwd' => '',
'dbname' => 'initphp_demo',
'charset' => 'utf8',
],
],
'log' => [
'level' => 'info',
'path' => APP_PATH . 'runtime/logs/',
],
];
<?php
// web/controller/IndexController.php
class IndexController extends Controller
{
public function run()
{
// 直接輸出
echo 'Hello InitPHP!';
// 或使用視圖
// $this->view->assign('title', '首頁');
// $this->view->display('index.html');
}
public function hello($name = 'World')
{
echo "Hello, {$name}!";
}
}
https://local.initphp.com/ → IndexController::run()https://local.initphp.com/?c=index&a=hello&name=InitPHP → IndexController::hello('InitPHP')project/
├── initphp/
├── app/ # 應用程式碼 (非 Web 可訪問)
│ ├── conf/
│ ├── controller/
│ └── model/
└── www/ # Web 根目錄
├── index.php # 入口
├── static/ # 靜態資源
└── .htaccess
入口文件調整:
<?php
// www/index.php
define('APP_PATH', __DIR__ . '/../app/');
define('INITPHP_PATH', __DIR__ . '/../initphp/');
require INITPHP_PATH . 'initphp.php';
InitPHP::setConfig(include APP_PATH . 'conf/comm.conf.php');
InitPHP::init();
api.php、admin.php 獨立入口InitPHP 以極簡核心提供企業級架構基礎,適合中小型專案快速落地。