启用大小写敏感Action配置
熟悉Zend Framework框架开发的开发者通常知晓,其MVC架构中的Controller和Action名称默认并不支持大小写混合,这令习惯驼峰式编码风格的程序员感到不便。不过,可以通过配置前端控制器FrontController的useCaseSensitiveActions参数,使Zend Framework能够识别大小写敏感的Controller与Action命名,具体实现代码如下: 复制代码 代码如下: $front = Zend_Controller_Front::getInstance();
$front->setParam('useCaseSensitiveActions',true); 配置完成后,若在AppController中定义了名为CoderBolgAction()的方法,访问该Action时需使用URL http://localhost/app/coder-bolg/,即在第二个大写字母前插入'-'字符。虽然这种格式不影响SEO甚至更利于搜索引擎优化,但随之而来的是URL本身变得严格区分大小写,一旦用户输入错误的大写字母便无法访问。为解决此问题,可在路由处理前将ModuleName、ControllerName和ActionName统一转为小写。具体做法是在继承自Zend_Controller_Action的项目基类的init()方法中添加以下三行代码: 复制代码 代码如下: $this->_request->setModuleName( strtolower( $this->_request->getModuleName() ) );
$this->_request->setControllerName(strtolower($this->_request->getControllerName()));
$this->_request->setActionName( strtolower( $this->_request->getActionName() ) ); 通过上述修改,即可彻底解决URL大小写敏感导致的访问失败问题。