Home >php教程 >php手册 >改写ThinkPHP的U方法使其路由下分页正常

改写ThinkPHP的U方法使其路由下分页正常

WBOY
WBOYOriginal
2016-06-13 09:32:091177browse

ThinkPHP3.1.3在启用路由的情况下,其分页地址不是路由的地址,由于thinkphp3.2.1的代码也没有修复,很多人都遇到了这一问题,本文采纳olcms的修改方法解决这一问题,特别感谢phper jack对此做出的贡献,具体解决办法是修改ThinkPHP的functions.php的U方法,在287行左右:

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

后面加入以下代码

/*
* 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替换为路由规则 
        }          
      }
    }
  }
 }

至此问题得以解决!

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