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