修改文件 /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. * * @access private * @return void */ 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); } 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,都是没有这一段的。
让CodeIgniter 直接支持RestFull 的修改方法,布布扣,bubuko.com
让CodeIgniter 直接支持RestFull 的修改方法
原文地址:http://blog.csdn.net/default7/article/details/38270713