Rewrite the U method of ThinkPHP to make the page under the route normal

Source: Internet
Author: User
This article mainly introduces how to rewrite the ThinkPHP U method so that the page under the route is normal. if you need it, refer to ThinkPHP.

ThinkPHP3.1.3 when routing is enabled, the paging address is not the routing address. because thinkphp3.2.1 code has not been fixed, many people have encountered this problem, this article uses the olcms modification method to solve this problem. thanks to phper jack for his contribution. the specific solution is to modify ThinkPHP functions. php's U method is about 287 rows:

If (! Empty ($ vars) {// add the parameter foreach ($ vars as $ var => $ val) {if (''! = Trim ($ val) $ url. = $ depr. $ var. $ depr. urlencode ($ val );}

Add the following code

/** The next page routing becomes invalid after tp is enabled. page-based URL assembly * // if the route if (C ('URL _ ROUTER_ON ') is enabled ')) {foreach (C ('URL _ ROUTE_RULES ') as $ zhaolg => $ zlig) {// traverse the route if (strstr ('/'. GROUP_NAME. $ url, $ zlig) {// find routing rules from the url $ lg = strstr ($ zhaolg, '/:'); // analysis rules with parameters? If ($ lg) {// if the rule includes the parameter $ tempzlg = str_replace ('/:', '', $ lg ); // take the parameter // dump ($ tempzlg); if ($ tempzlg) {if (C ('app _ SUB_DOMAIN_DEPLOY ') {$ zlgurl = str_replace ($ zlig, $ zhaolg ,'/'. GROUP_NAME. $ url); // replace the url with the routing rule} else {$ zlgurl = str_replace ($ zlig, $ zhaolg, $ url ); // replace the url with the routing rule} // note/s/: c/4/p/_ PAGE _/dump ($ zlgurl ); $ url = str_replace ($ lg. '/'. $ tempzlg, '', $ zlgurl); // replace the routing rule parameter} else {// The analysis rule does not contain the parameter if (C ('app _ SUB_DOMAIN_DEPLOY ')) {$ url = str_replace ($ zlig, $ zhaolg ,'/'. GROUP_NAME. $ url); // replace the url with the routing rule} else {$ url = str_replace ($ zlig, $ zhaolg, $ url ); // replace the url with the routing rule }}}}}

Now the problem has been solved!

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.