Yii 是高效能、基於元件的 PHP5 框架,嚴格遵循 OOP、MVC、DAO/ActiveRecord、快取、RBAC、I18N/L10N 等企業級特性。透過 yiic 命令列工具快速生成專案骨架。
yiiframework.com) 解壓至 Web 可存取目錄。https://host/yii/requirements/index.php 檢查環境需求 (PDO、MBstring、GD 等)。結論顯示「滿足最低需求」即可。$ cd /WebRoot/testdrive/framework
$ ./yiic webapp ../../testdrive
# 確認 Yes,自動生成目錄結構
testdrive/
├── index.php # 入口腳本
├── protected/ # 受保護應用目錄 (不可直接 Web 存取)
│ ├── config/main.php # 主配置
│ ├── controllers/ # 控制器
│ ├── models/ # 模型
│ ├── views/ # 視圖
│ └── runtime/ # 臨時檔案 (需可寫)
├── assets/ # 發佈資源 (CSS/JS/圖片)
├── css/, images/, themes/
└── yiic, yiic.php, yiic.bat
<?php
return array(
'components'=>array(
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false, // 關鍵:隱藏 index.php
'rules'=>array(
'sites' => 'site/index',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
),
);
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
server {
root /www/mysite/htdocs;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/(protected|framework|themes/\w+/views) { deny all; }
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
瀏覽 https://host/testdrive/sites 應正確路由至 SiteController::actionIndex(),URL 中無 index.php。