Overwrite the U method of ThinkPHP to make its route paging normal
- 2021-07-07 06:38:44
- OfStack
When ThinkPHP3.1. 3 is enabled for routing, its paging address is not the address of routing. Because the code of thinkphp3.2. 1 has not been repaired, many people have encountered this problem. This paper adopts the modification method of olcms to solve this problem, especially thanks to phper jack for its contribution. The specific solution is to modify functions of ThinkPHP. U method of php, in about 287 lines:
if(!empty($vars)) {
// Add parameters
foreach ($vars as $var => $val){
if('' !== trim($val))
$url .= $depr . $var . $depr . urlencode($val);
}
Add the following code after it
/*
* tp After opening the route, 1 Page routing failure problem Paging class URL Assemble
*/
// If routing is turned on
if(C('URL_ROUTER_ON')){
foreach (C('URL_ROUTE_RULES') as $zhaolg => $zlig){// Traversing route
if(strstr('/'.GROUP_NAME.$url,$zlig)){// Find routing rules from URLs
$lg = strstr($zhaolg,'/:');// Analysis rule With parameters ?
if($lg){// If the rule takes parameters
$tempzlg = str_replace('/:','',$lg);// Take parameters
//dump($tempzlg);
if($tempzlg){
if(C('APP_SUB_DOMAIN_DEPLOY')){
$zlgurl = str_replace($zlig,$zhaolg,'/'.GROUP_NAME.$url); //url Replace with routing rules
}else{
$zlgurl = str_replace($zlig,$zhaolg,$url); //url Replace with routing rules
}
// Note /s/:c/c/4/p/__PAGE__
//dump($zlgurl);
$url = str_replace($lg.'/'.$tempzlg,'',$zlgurl);//url Replace routing rule parameters
}
}else{// Analysis rule Without parameters
if(C('APP_SUB_DOMAIN_DEPLOY')){
$url = str_replace($zlig,$zhaolg,'/'.GROUP_NAME.$url);//url Replace with routing rules
}else{
$url = str_replace($zlig,$zhaolg,$url);//url Replace with routing rules
}
}
}
}
}
At this point, the problem has been solved!