码迷,mamicode.com
首页 > 其他好文 > 详细

让CodeIgniter 直接支持RestFull 的修改方法

时间:2014-07-29 18:05:12      阅读:211      评论:0      收藏:0      [点我收藏+]

标签: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.
	 *
	 * @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 的修改方法

标签:codeigniter   route   restfull   

原文地址:http://blog.csdn.net/default7/article/details/38270713

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!