有用過Zend Framework框架開發過項目的網友都知道 Zend Framework (ZF) MVC中的Controller和Action名稱默認是不支持大小寫的,這對於已經習慣了駝峯式代碼風格的開發人員來講,顯然是難以接受的。還好能夠設 定前端控制器FrontController的useCaseSensitiveActions參數來讓Zend Framework支持大小寫的Controller與Action命名,代碼以下:前端
$front = Zend_Controller_Front::getInstance(); $front->setParam('useCaseSensitiveActions',true);
如今若是在 AppController中定義了一個Action叫作 CoderBolgAction();而要訪問這個Action時,URL要寫 http://localhost/app/coder-bolg/,注意Action的第二個大寫字母前加上了'-'。這個倒還沒事,至少問題解決了, 並且加上'-'也不影響SEO,甚至比駝峯式對搜索引擎更爲友好。可是又出現了一個讓人更沒法容忍的問題:URL也區別大小寫了。就是說若是用戶在URL 中把Action的某個字母輸入成了大寫就沒法顯示。暈死……,不過這個也比較好解決。在路由前把ModuleName 、ControllerName 、ActionName 都修改爲小寫就解決了。我在Zend_Controller_Action的子類(在咱們的項目中讓這個子類繼承 Zend_Controller_Action,咱們的Controller再繼承這個類)的init()方法中加上這三行:app
$this->_request->setModuleName( strtolower( $this->_request->getModuleName() ) ); $this->_request->setControllerName(strtolower($this->_request->getControllerName())); $this->_request->setActionName( strtolower( $this->_request->getActionName() ) );
這樣就解決了URL大小寫敏感的問題。框架