diff options
author | Andrey Andreev <narf@devilix.net> | 2013-11-11 12:48:45 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2013-11-11 12:48:45 +0100 |
commit | af709d6ebe6ca75913d7a9eedb4fdcd76be45c50 (patch) | |
tree | 8b0094b140830bbf9baa13529ceed77658b12a61 /system/core | |
parent | 0949b36c3ebb10732223ddc890e1a41c015aa086 (diff) | |
parent | 0b58b3cad456efc5ecce89f622876c6b715439c2 (diff) |
Merge pull request #2712 from pveyes/develop
Enable HTTP Verb in Routing
Diffstat (limited to 'system/core')
-rw-r--r-- | system/core/Router.php | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/system/core/Router.php b/system/core/Router.php index 0f7278ae6..9071f84b7 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -345,15 +345,42 @@ class CI_Router { // Turn the segment array into a URI string $uri = implode('/', $this->uri->segments); + // Get HTTP verb + $http_verb = strtolower($_SERVER['REQUEST_METHOD']); + // Is there a literal match? If so we're done - if (isset($this->routes[$uri]) && is_string($this->routes[$uri])) + if (isset($this->routes[$uri])) { - return $this->_set_request(explode('/', $this->routes[$uri])); + // Check default routes format + if (is_string($this->routes[$uri])) + { + return $this->_set_request(explode('/', $this->routes[$uri])); + } + // Is there any matching http verb? + elseif (is_array($this->routes[$uri]) && isset($this->routes[$uri][$http_verb])) + { + return $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); + } } // Loop through the route array looking for wildcards foreach ($this->routes as $key => $val) { + // Check if route format is using http verb + if (is_array($val)) + { + // Does the http verb match? + if (isset($val[$http_verb])) + { + $val = $val[$http_verb]; + } + // No match, skip to next rule + else + { + continue; + } + } + // Convert wildcards to RegEx $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); |