Home > php教程 > php手册 > 关于U方法的 根据路由配置自动更新地址

关于U方法的 根据路由配置自动更新地址

WBOY
Release: 2016-06-07 11:39:46
Original
970 people have browsed it

关于U方法的 根据路由配置自动更新地址
网上无意中看到的。不知道火星没
修改Common\functions.phpif(!empty($vars)) { // 添加参数<br>     foreach ($vars as $var => $val){<br>         if('' !== trim($val))   $url .= $depr . $var . $depr . urlencode($val);<br> }后面加入以下代码:(3.2版本把GROUP_NAME换成MODULE_NAME)/*<br> * tp开启路由之后下一页路由失效问题 分页类URL组装<br> * modify author :赵利刚 王荣<br> * modify time:2014.3.5<br> */<br> //如果开启路由<br> if(C('URL_ROUTER_ON')){            <br>     foreach (C('URL_ROUTE_RULES') as $zhaolg => $zlig){//遍历路由                      <br>         if(strstr('/'.GROUP_NAME.$url,$zlig)){//从网址中找路由规则<br>             $lg = strstr($zhaolg,'/:');//分析规则 带参数?<br>             if($lg){//如果规则带参数                          <br>                 $tempzlg = str_replace('/:','',$lg);//取参数<br>                 //dump($tempzlg);  <br>                 if($tempzlg){<br>                     if(C('APP_SUB_DOMAIN_DEPLOY')){<br>                         $zlgurl = str_replace($zlig,$zhaolg,'/'.GROUP_NAME.$url); //url替换为路由规则 <br>                     }else{<br>                         $zlgurl = str_replace($zlig,$zhaolg,$url); //url替换为路由规则 <br>                     }                              <br>                     //注 /s/:c/c/4/p/__PAGE__<br>                     //dump($zlgurl);<br>                     $url = str_replace($lg.'/'.$tempzlg,'',$zlgurl);//url替换路由规则参数<br>                                                  <br>                 }  <br>             }else{//分析规则  不带参数<br>                 if(C('APP_SUB_DOMAIN_DEPLOY')){<br>                     $url = str_replace($zlig,$zhaolg,'/'.GROUP_NAME.$url);//url替换为路由规则<br>                 }else{<br>                     $url = str_replace($zlig,$zhaolg,$url);//url替换为路由规则 <br>                 }                  <br>  <br>             }<br>         }<br>     }<br> }进行如上修改后,U方法不用再根据路由规则手动进行修改。这样可以方便路由规则更新时,模板文件不用进行修改。
经本人测试,nginx下无效,apache有效。

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template