Solution to the url case-sensitivity issue in the zendframework framework _ php instance

Source: Internet
Author: User
This article describes how to solve the url case-sensitivity problem in the zendframework framework, including the case sensitivity of the action Controller and request URL, anyone who needs it can refer to anyone who has used the Zend Framework to develop projects knows that the Controller and Action names in Zend Framework (ZF) MVC do not support case sensitivity by default, this is obviously unacceptable for developers who are used to camper code. Fortunately, you can set the useCaseSensitiveActions parameter of the front-end Controller FrontController to name Zend Framework controllers and actions in case. the code is as follows:

The code is as follows:


$ Front = Zend_Controller_Front: getInstance ();

$ Front-> setParam ('usecasesensitiveactions ', true );


If an Action is defined in AppController as CoderBolgAction (), http: // localhost/app/coder-bolg/is required for the URL to access this Action /, note that '-' is added before the second uppercase letter of Action '-'. This is okay, at least the problem is solved, and the addition of '-' does not affect SEO, or even more friendly than the camper type for search engines. However, there is a more intolerable problem: The URL is also case sensitive. That is to say, if a user enters a letter of Action in the URL, it cannot be displayed. Dizzy ......, However, this is a better solution. Modify ModuleName, ControllerName, and ActionName to lowercase before routing. In the init () method of Zend_Controller_Action, I add these three lines to the init () method:

The code is as follows:


$ This-> _ request-> setModuleName (strtolower ($ this-> _ request-> getModuleName ()));

$ This-> _ request-> setControllerName (strtolower ($ this-> _ request-> getControllerName ()));

$ This-> _ request-> setActionName (strtolower ($ this-> _ request-> getActionName ()));


In this way, the URL is case sensitive.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.