legacy CakePHP routing
目的
整理 get-lancer-php56 legacy CakePHP 專案的 path 如何對應到 controller / action。
主要來源
app/Config/routes.php
app/Config/cms_routes.php
CakePHP controller/action convention
plugin controller pathroutes.php 會:
App::import('Lib', 'CmsRouter');
require_once 'cms_routes.php';
CmsRouter::localize();
require CAKE . 'Config' . DS . 'routes.php';因此 legacy 查 route 時不能只看 routes.php。如果 routes 沒明確設定,還要看 CakePHP convention 與 plugin controller。
常見 path convention
legacy URL 可能直接對應 controller action:
/quote_bids/provider_accept_narrow_match/{id}.json
-> app/Plugin/Quotes/Controller/QuoteBidsController.php
-> QuoteBidsController::provider_accept_narrow_match($id)/quote_requests/search_add.json
-> app/Plugin/Quotes/Controller/QuoteRequestsController.php
-> QuoteRequestsController::search_add()Plugin path 常見位置:
app/Plugin/Quotes/Controller/*Controller.php
app/Plugin/Quotes/Model/*.php查詢順序
- 用 URL 找 controller/action 名稱。
- 先查
app/Config/routes.php是否有明確 route。 - 查
app/Config/cms_routes.php是否有 localize / CMS route 影響。 - 依 CakePHP convention 查 plugin controller。
- 在 controller action 內追 model/domain method。
- 查 action 如何讀 request data、named params、path params。
- 查 auth/session/security hash guard。
常見陷阱
- 沒有 routes 設定不代表 endpoint 不存在,可能靠 CakePHP convention。
.json通常是 RequestHandler / response format,不一定出現在 action method 名稱。- plugin controller path 會影響 URL 到 controller 的推導。
- legacy action 可能用
$this->params['named']、$this->request->data、method arguments 混合讀參數。 - legacy
ProException::getMessageKey()回的可能是翻譯後文字或 message key,需看 controller handler。