_php instance of a method for thinkphp to support case-sensitive URL address access

Source: Internet
Author: User

The example in this article describes a method that lets thinkphp support case-and-write URL address access. Share to everyone for your reference. The implementation methods are as follows:

Usually thinkphp by default is a case-sensitive URL, this is the same as the Linux system in the lowercase URL is two different names, but we use Windows accustomed to the same as the case, so we still have to deal with the problem according to user habits, the following we look at the problem solving method.

The thinkphp case recognition feature is turned on in the configuration file so that the case of the link can be accessed properly:
' Url_case_insensitive ' =>true
File naming is canonical, but when you use __url__ in the template to get the current URL path, you do not get the URL correctly.
This is written in the manual:
Here is a place to note that if we define a Usertypeaction module class, then the URL should be accessed by:
Http://serverName/index.php/user_type/list
Instead of
Http://serverName/index.php/usertype/list
The link to use __url__ in the template or the one below is not underlined.
This problem on the Internet also has a lot of people feedback, there is a solution is to modify the TP source code:
In the Dispatcher.class.php file in the core folder of the TP Lib folder, find 181 rows, where the __url__ address is defined:

Copy Code code as follows:
$moduleName = defined (' Module_alias ')? Module_alias:module_name;
if (defined (' Group_name ')) {
Define (' __url__ ',!empty ($domainModule)? __group__. $depr: __group__. $depr. ( C (' url_case_insensitive ')? Strtolower ($moduleName): $moduleName));
}else{
Define (' __url__ ',!empty ($domainModule)? __app__. ' /': __app__. ' /'. (C (' url_case_insensitive ') strtolower ($moduleName): $moduleName));
}

Put the
Copy Code code as follows:
C (' url_case_insensitive ')? Strtolower ($moduleName): $moduleName)
Change into:
Copy Code code as follows:
C (' url_case_insensitive ') parse_name ($moduleName, 0): $moduleName

So the problem is done!

I hope this article will be helpful to everyone's thinkphp framework program design.

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.