Solution of url Case Problem in zend framework Framework

  • 2021-07-13 04:31:54
  • OfStack

Netizens who have used Zend Framework framework to develop projects know that Controller and Action names in Zend Framework (ZF) MVC do not support case by default, which is obviously unacceptable to developers who are used to hump code style. Fortunately, you can set the useCaseSensitiveActions parameter of the front-end controller FrontController to make Zend Framework support the naming of Controller and Action in case. The code is as follows:


$front = Zend_Controller_Front::getInstance(); $front->setParam('useCaseSensitiveActions',true);

Now if an Action is defined in AppController, it is called CoderBolgAction (); To access this Action, URL should write http://localhost/app/coder-bolg/, and notice that the second capital letter of Action is preceded by '-'. This is okay, at least the problem is solved, and adding '-' doesn't affect SEO, even more friendly to search engines than hump. But there is another more intolerable problem: URL is also case-sensitive. That is to say, if the user enters a letter of Action in URL in uppercase, it cannot be displayed. Dizzy..., but this is also easier to solve. Before routing, modify ModuleName, ControllerName and ActionName to lowercase. I added these three lines to the init () method of the subclass of Zend_Controller_Action (which in our project inherited Zend_Controller_Action, which our Controller inherited again):

$this->_request->setModuleName( strtolower( $this->_request->getModuleName() ) ); $this->_request->setControllerName(strtolower($this->_request->getControllerName())); $this->_request->setActionName( strtolower( $this->_request->getActionName() ) );

This solves the case sensitivity of URL.


Related articles: