function _parse_routes() { $rest_routes = map_resources(); // we do this for performence if (empty($rest_routes) && count($this->routes) == 1) { $this->_set_request($this->uri->segments); return; } // also this... $uri = implode('/', $this->uri->segments); if (isset($this->routes[$uri])) { $this->_set_request(explode('/', $this->routes[$uri])); return; } // RESTful url matching... $request_method = $_SERVER['REQUEST_METHOD']; $routes = isset($rest_routes[$request_method]) && $rest_routes[$request_method] ? $rest_routes[$request_method] : array(); foreach ($routes as $pattern => $replace) { $pattern = str_replace(':id', '[^/]+', $pattern); // use this to match non-numeric id field $pattern = str_replace(':any', '.+', $pattern); $pattern = str_replace(':num', '[0-9]+', $pattern); $pattern = str_replace(':uuid', '[a-zA-Z0-9]{8}(-[a-zA-Z0-9]{4}){3}-[a-zA-Z0-9]{12}', $pattern); // Does the RegEx match? if (preg_match("#^{$pattern}\$#", $uri)) { // Do we have a back-reference? if (strpos($replace, '$') !== FALSE && strpos($pattern, '(') !== FALSE) { $replace = preg_replace("#^{$pattern}\$#", $replace, $uri); } // we are done $this->_set_request(explode('/', $replace)); return; } } // if non of the rules match, then go on... parent::_parse_routes(); }
| | There are two reserved routes: | | $route['default_controller'] = 'welcome'; | | This route indicates which controller class should be loaded if the | URI contains no data. In the above example, the "welcome" class | would be loaded. | | $route['scaffolding_trigger'] = 'scaffolding'; | | This route lets you set a "secret" word that will trigger the | scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. The reserved | routes must come before any wildcard or regular expression routes. | */ $route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = ""; // RESTful style url map_resources('users'); // If you don't want custom action handler, just skip code below... // custom action handles GET request map_resources('GET', 'users/(:id)/custom_action', 'users/custom_action/$1'); // some other custom action mappings... // custom action handles PUT request //map_resources('users/(:id)/custom_action', 'sync_sessions/custom_action/$1', 'PUT'); // custom action handles all request method //map_resources('users/(:id)/custom_action', 'sync_sessions/custom_action/$1'); /* End of file routes.php */ /* Location: ./system/application/config/routes.php */