让codeigniter 路由支持只能解析带问号的重写!

配置路由,网址 http://www.***.com/info/cat-13479-13487-0/ 的实际访问 方法为 info/lst?type=cat&v1=$1&v2=$2&v3=$3 方法:

修改文件: system/core/Router.php 的方法:

_parse_routes()加入如下一句:



//2014-11-16 12:19 add by f.z.b
if(strpos($val,'?') !== false){
    list($val,$queryString) = explode('?',$val);
    parse_str($queryString,$_GET);
}


整个方法的代码:

function _parse_routes()
{
   // Turn the segment array into a URI string
   $uri = implode('/', $this->uri->segments);

   // Is there a literal match?  If so we're done
   if (isset($this->routes[$uri]))
   {
      return $this->_set_request(explode('/', $this->routes[$uri]));
   }

   // Loop through the route array looking for wild-cards
   foreach ($this->routes as $key => $val)
   {
      // Convert wild-cards to RegEx
      $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));

      // Does the RegEx match?
      if (preg_match('#^'.$key.'$#', $uri))
      {
         // Do we have a back-reference?
         if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE)
         {
            $val = preg_replace('#^'.$key.'$#', $val, $uri);
         }

               //2014-11-16 12:19 add by f.z.b
               if(strpos($val,'?') !== false){
                   list($val,$queryString) = explode('?',$val);
                   parse_str($queryString,$_GET);
               }

         return $this->_set_request(explode('/', $val));
      }
   }

   // If we got this far it means we didn't encounter a
   // matching route so we'll set the site default route
   $this->_set_request($this->uri->segments);
}


配置路由: application/config/routes.php

$route['info/cat-(:num)-(:num)-(:num)'] = 'info/lst/1?type=cat&v1=$1&v2=$2&v3=$3';


    public function lst($page = 1)
    {
        if ($page < 1) $page = 1;

        $type = $this->input->get('type');
        if($type == 'diqu'){
            $v1 = $this->input->get('v1');
            $v2 = $this->input->get('v2');
            $v3 = $this->input->get('v3');

        } else {

        }


    }

#文 default.fu@foxmail.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值