The URL of the U method is automatically updated based on the route configuration.

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn about the U method and automatically update the address based on the route configuration.
You can see it on the Internet. I don't know about Mars.
Modify Common \ functions. php If (! Empty ($ vars) {// Add Parameters
Foreach ($ vars as $ var => $ val ){
If (''! = Trim ($ val) $ url. = $ depr. $ var. $ depr. urlencode ($ val );
}
Add the following code: (replace GROUP_NAME with MODULE_NAME in version 3.2) /*
* When tp enables a route entry, the next route entry becomes invalid. Paging URL assembly
* Modify author: WANG Rong, Zhao Ligang
* Modify time: 2014.3.5
*/
// If routing is enabled
If (C ('url _ ROUTER_ON ')){
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, '/:'); // does the analysis rule contain parameters?
If ($ lg) {// if the rule contains Parameters
$ Tempzlg = str_replace ('/:', ', $ lg); // obtain 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 routing rule parameters with URLs

}
} Else {// The analysis rule does not contain parameters
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
}

}
}
}
}
After the preceding modification, you do not need to manually modify the U method based on the routing rules. This makes it easier to update routing rules without modifying the template file.
According to my test, nginx is invalid and apache is valid.

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.