首页 > 其他 > 详细

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

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

修改文件 /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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!