Zend Framework 中,Zend_Controller 測試時遇到的問題

我有三天的時間卡在 Zend_Controller 的使用問題,不管怎麼用都會丟出 500 Internal Server Error。後來不斷的測試,發現他根本就會動,只是我測試的方法有問題。

先講一下 Zend_Controller 的用法,在引入 Zend_Controller_Front class 後 (方法請參考官方網站的說明):

  • 先用 $ctrl = Zend_Controller_Front::getInstance(); 取得 controller。(跟 I HAVE CONTROL 無關... 看不懂笑點的請參考 CLANNAD 00)
  • $ctrl->setParam('noViewRenderer', TRUE); 將預設啟用的 Renderer Helper 閹掉。
  • 然後用 $ctrl->addControllerDirectory('目錄位置'); 設定 Controller 目錄。
  • 最後用 $ctrl->dispatch(); 開始跑。

然後 controller 的目錄下放 IndexController.php 就會對應 http://host/index 以及 http://host/ (因為 index 是特殊的存在),放 TestController.php 就會對應 http://host/test,這些在官方文件裡都有還算清楚的範例。

我的錯誤是在,我錯誤的使用 GET 的 proxy 模擬 HTTP Request。簡單的說,以下的 HTTP Request 會造成 500:

GET http://test.host.domain/test HTTP/1.1
Host: test.host.domain

但這個不會:

GET /test HTTP/1.1
Host: test.host.domain

而我用 libwww-perl 內附的 GET 這個「指令」測試:

GET -SUe -p http://test.host.domain:80/ http://test.host.domain/test

這個指令會送出第一類 HTTP Request,於是就噴了... 就只是這樣的問題而已。

Leave a Reply

Your email address will not be published. Required fields are marked *