標籤:codeigniter route restfull
修改檔案 /system/core/Router.php 的方法 _parse_route()
/** * Parse Routes * * This function matches any routes that may exist in * the config/routes.php file against the URI to * determine if the class/method need to be remapped. * * @accessprivate * @returnvoid */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 doneif (isset($this->routes[$uri])){return $this->_set_request(explode('/', $this->routes[$uri]));}// Loop through the route array looking for wild-cardsforeach ($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);}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
$routes['index'] = array('get'=>'news/lst','post'=>'news/lst','put'=>'news/lst',);
by default7#zbphp.com
特別備忘,從官網和中文CI網站下載來的CI 2.2 /2.1 包括從github官網下載來的CI,都是沒有這一段的。