Public Member Functions | |
| CI_Router () | |
| Constructor. | |
| _set_routing () | |
| Set the route mapping. | |
| _set_request ($segments=array()) | |
| Set the Route. | |
| _validate_request ($segments) | |
| Validates the supplied segments. | |
| _parse_routes () | |
| Parse Routes. | |
| set_class ($class) | |
| Set the class name. | |
| fetch_class () | |
| Fetch the current class. | |
| set_method ($method) | |
| Set the method name. | |
| fetch_method () | |
| Fetch the current method. | |
| set_directory ($dir) | |
| Set the directory name. | |
| fetch_directory () | |
| Fetch the sub-directory (if any) that contains the requested controller class. | |
Public Attributes | |
| $config | |
| $routes = array() | |
| $error_routes = array() | |
| $class = '' | |
| $method = 'index' | |
| $directory = '' | |
| $uri_protocol = 'auto' | |
| $default_controller | |
| $scaffolding_request = FALSE | |
Definition at line 29 of file Router.php.
| CI_Router::_parse_routes | ( | ) |
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.
private
Definition at line 243 of file Router.php.
References _set_request().
Referenced by _set_routing().
00244 { 00245 // Do we even have any custom routing to deal with? 00246 // There is a default scaffolding trigger, so we'll look just for 1 00247 if (count($this->routes) == 1) 00248 { 00249 $this->_set_request($this->uri->segments); 00250 return; 00251 } 00252 00253 // Turn the segment array into a URI string 00254 $uri = implode('/', $this->uri->segments); 00255 00256 // Is there a literal match? If so we're done 00257 if (isset($this->routes[$uri])) 00258 { 00259 $this->_set_request(explode('/', $this->routes[$uri])); 00260 return; 00261 } 00262 00263 // Loop through the route array looking for wild-cards 00264 foreach ($this->routes as $key => $val) 00265 { 00266 // Convert wild-cards to RegEx 00267 $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); 00268 00269 // Does the RegEx match? 00270 if (preg_match('#^'.$key.'$#', $uri)) 00271 { 00272 // Do we have a back-reference? 00273 if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) 00274 { 00275 $val = preg_replace('#^'.$key.'$#', $val, $uri); 00276 } 00277 00278 $this->_set_request(explode('/', $val)); 00279 return; 00280 } 00281 } 00282 00283 // If we got this far it means we didn't encounter a 00284 // matching route so we'll set the site default route 00285 $this->_set_request($this->uri->segments); 00286 }


| CI_Router::_set_request | ( | $ | segments = array() |
) |
Set the Route.
This function takes an array of URI segments as input, and sets the current class/method
private
| array | ||
| bool |
Definition at line 139 of file Router.php.
References _validate_request(), set_class(), and set_method().
Referenced by _parse_routes(), and _set_routing().
00140 { 00141 $segments = $this->_validate_request($segments); 00142 00143 if (count($segments) == 0) 00144 { 00145 return; 00146 } 00147 00148 $this->set_class($segments[0]); 00149 00150 if (isset($segments[1])) 00151 { 00152 // A scaffolding request. No funny business with the URL 00153 if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') 00154 { 00155 $this->scaffolding_request = TRUE; 00156 unset($this->routes['scaffolding_trigger']); 00157 } 00158 else 00159 { 00160 // A standard method request 00161 $this->set_method($segments[1]); 00162 } 00163 } 00164 else 00165 { 00166 // This lets the "routed" segment array identify that the default 00167 // index method is being used. 00168 $segments[1] = 'index'; 00169 } 00170 00171 // Update our "routed" segment array to contain the segments. 00172 // Note: If there is no custom routing, this array will be 00173 // identical to $this->uri->segments 00174 $this->uri->rsegments = $segments; 00175 }


| CI_Router::_set_routing | ( | ) |
Set the route mapping.
This function determines what should be served based on the URI request, as well as any "routes" that have been set in the routing config file.
private
Definition at line 65 of file Router.php.
References $route, _parse_routes(), _set_request(), log_message(), set_class(), set_method(), and show_error().
Referenced by CI_Router().
00066 { 00067 // Are query strings enabled in the config file? 00068 // If so, we're done since segment based URIs are not used with query strings. 00069 if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) 00070 { 00071 $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); 00072 00073 if (isset($_GET[$this->config->item('function_trigger')])) 00074 { 00075 $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); 00076 } 00077 00078 return; 00079 } 00080 00081 // Load the routes.php file. 00082 @include(APPPATH.'config/routes'.EXT); 00083 $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; 00084 unset($route); 00085 00086 // Set the default controller so we can display it in the event 00087 // the URI doesn't correlated to a valid controller. 00088 $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); 00089 00090 // Fetch the complete URI string 00091 $this->uri->_fetch_uri_string(); 00092 00093 // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. 00094 if ($this->uri->uri_string == '') 00095 { 00096 if ($this->default_controller === FALSE) 00097 { 00098 show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); 00099 } 00100 00101 $this->set_class($this->default_controller); 00102 $this->set_method('index'); 00103 $this->_set_request(array($this->default_controller, 'index')); 00104 00105 // re-index the routed segments array so it starts with 1 rather than 0 00106 $this->uri->_reindex_segments(); 00107 00108 log_message('debug', "No URI present. Default controller set."); 00109 return; 00110 } 00111 unset($this->routes['default_controller']); 00112 00113 // Do we need to remove the URL suffix? 00114 $this->uri->_remove_url_suffix(); 00115 00116 // Compile the segments into an array 00117 $this->uri->_explode_segments(); 00118 00119 // Parse any custom routing that may exist 00120 $this->_parse_routes(); 00121 00122 // Re-index the segment array so that it starts with 1 rather than 0 00123 $this->uri->_reindex_segments(); 00124 }


| CI_Router::_validate_request | ( | $ | segments | ) |
Validates the supplied segments.
Attempts to determine the path to the controller.
private
| array |
Definition at line 187 of file Router.php.
References fetch_directory(), set_class(), set_directory(), set_method(), and show_404().
Referenced by _set_request().
00188 { 00189 // Does the requested controller exist in the root folder? 00190 if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) 00191 { 00192 return $segments; 00193 } 00194 00195 // Is the controller in a sub-folder? 00196 if (is_dir(APPPATH.'controllers/'.$segments[0])) 00197 { 00198 // Set the directory and remove it from the segment array 00199 $this->set_directory($segments[0]); 00200 $segments = array_slice($segments, 1); 00201 00202 if (count($segments) > 0) 00203 { 00204 // Does the requested controller exist in the sub-folder? 00205 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) 00206 { 00207 show_404($this->fetch_directory().$segments[0]); 00208 } 00209 } 00210 else 00211 { 00212 $this->set_class($this->default_controller); 00213 $this->set_method('index'); 00214 00215 // Does the default controller exist in the sub-folder? 00216 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) 00217 { 00218 $this->directory = ''; 00219 return array(); 00220 } 00221 00222 } 00223 00224 return $segments; 00225 } 00226 00227 // Can't find the requested controller... 00228 show_404($segments[0]); 00229 }


| CI_Router::CI_Router | ( | ) |
Constructor.
Runs the route mapping function.
Definition at line 46 of file Router.php.
References _set_routing(), load_class(), and log_message().
00047 { 00048 $this->config =& load_class('Config'); 00049 $this->uri =& load_class('URI'); 00050 $this->_set_routing(); 00051 log_message('debug', "Router Class Initialized"); 00052 }

| CI_Router::fetch_class | ( | ) |
Fetch the current class.
public
Definition at line 310 of file Router.php.
Referenced by fetch_method().

| CI_Router::fetch_directory | ( | ) |
Fetch the sub-directory (if any) that contains the requested controller class.
public
Definition at line 369 of file Router.php.
Referenced by _validate_request().

| CI_Router::fetch_method | ( | ) |
Fetch the current method.
public
Definition at line 337 of file Router.php.
References fetch_class().
00338 { 00339 if ($this->method == $this->fetch_class()) 00340 { 00341 return 'index'; 00342 } 00343 00344 return $this->method; 00345 }

| CI_Router::set_class | ( | $ | class | ) |
Set the class name.
public
| string |
Definition at line 297 of file Router.php.
References $class.
Referenced by _set_request(), _set_routing(), and _validate_request().
00298 { 00299 $this->class = $class; 00300 }

| CI_Router::set_directory | ( | $ | dir | ) |
Set the directory name.
public
| string |
Definition at line 356 of file Router.php.
Referenced by _validate_request().

| CI_Router::set_method | ( | $ | method | ) |
Set the method name.
public
| string |
Definition at line 324 of file Router.php.
References $method.
Referenced by _set_request(), _set_routing(), and _validate_request().
00325 { 00326 $this->method = $method; 00327 }

| CI_Router::$class = '' |
| CI_Router::$config |
Definition at line 31 of file Router.php.
| CI_Router::$default_controller |
Definition at line 38 of file Router.php.
| CI_Router::$directory = '' |
Definition at line 36 of file Router.php.
| CI_Router::$error_routes = array() |
Definition at line 33 of file Router.php.
| CI_Router::$method = 'index' |
| CI_Router::$routes = array() |
Definition at line 32 of file Router.php.
| CI_Router::$scaffolding_request = FALSE |
Definition at line 39 of file Router.php.
| CI_Router::$uri_protocol = 'auto' |
Definition at line 37 of file Router.php.