让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 {

        }


    }

#文 [email protected]

你可能感兴趣的:(codeigniter)