Home >Backend Development >PHP Tutorial >Rewrite ThinkPHP's U method to make paging under routing normal_PHP tutorial

Rewrite ThinkPHP's U method to make paging under routing normal_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:28814browse

When routing is enabled in ThinkPHP3.1.3, its paging address is not the routing address. Since the code of thinkphp3.2.1 has not been repaired, many people have encountered this problem. This article adopts the modification method of olcms to solve this problem. , special thanks to phper jack for his contribution to this. The specific solution is to modify the U method of ThinkPHP's functions.php, which is around line 287:

 if(!empty($vars)) { 
 // 添加参数
 foreach ($vars as $var => $val){
 if('' !== trim($val))
 $url .= $depr . $var . $depr . urlencode($val);
 }

Add the following code after it

/*
* tp开启路由之后下一页路由失效问题 分页类URL组装
*/
 //如果开启路由
 if(C('URL_ROUTER_ON')){        
  foreach (C('URL_ROUTE_RULES') as $zhaolg => $zlig){//遍历路由            
    if(strstr('/'.GROUP_NAME.$url,$zlig)){//从网址中找路由规则
      $lg = strstr($zhaolg,'/:');//分析规则 带参数?
      if($lg){//如果规则带参数              
        $tempzlg = str_replace('/:','',$lg);//取参数
        //dump($tempzlg); 
        if($tempzlg){
          if(C('APP_SUB_DOMAIN_DEPLOY')){
            $zlgurl = str_replace($zlig,$zhaolg,'/'.GROUP_NAME.$url); //url替换为路由规则 
          }else{
            $zlgurl = str_replace($zlig,$zhaolg,$url); //url替换为路由规则 
          }                
          //注 /s/:c/c/4/p/__PAGE__
          //dump($zlgurl);
          $url = str_replace($lg.'/'.$tempzlg,'',$zlgurl);//url替换路由规则参数
                        
        }  
      }else{//分析规则 不带参数
        if(C('APP_SUB_DOMAIN_DEPLOY')){
          $url = str_replace($zlig,$zhaolg,'/'.GROUP_NAME.$url);//url替换为路由规则
        }else{
          $url = str_replace($zlig,$zhaolg,$url);//url替换为路由规则 
        }          
      }
    }
  }
 }

This problem is solved!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824664.htmlTechArticleWhen routing is enabled, the paging address of ThinkPHP3.1.3 is not the routing address, due to the code of thinkphp3.2.1 There is no fix. Many people have encountered this problem. This article adopts olcm...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn