blob: 748678d6743f92bc478de243a5db944ea59aa13d [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Router Class
32 *
33 * Parses URIs and determines routing
34 *
35 * @package CodeIgniter
36 * @subpackage Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050037 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000038 * @category Libraries
39 * @link http://codeigniter.com/user_guide/general/routing.html
40 */
41class CI_Router {
42
David Behler07b53422011-08-15 00:25:06 +020043 /**
44 * Config class
45 *
46 * @var object
47 * @access public
48 */
Barry Mienydd671972010-10-04 16:33:58 +020049 var $config;
David Behler07b53422011-08-15 00:25:06 +020050 /**
51 * List of routes
52 *
53 * @var array
54 * @access public
55 */
Barry Mienydd671972010-10-04 16:33:58 +020056 var $routes = array();
David Behler07b53422011-08-15 00:25:06 +020057 /**
58 * List of error routes
59 *
60 * @var array
61 * @access public
62 */
Derek Allard2067d1a2008-11-13 22:59:24 +000063 var $error_routes = array();
David Behler07b53422011-08-15 00:25:06 +020064 /**
65 * Current class name
66 *
67 * @var string
68 * @access public
69 */
Derek Allard2067d1a2008-11-13 22:59:24 +000070 var $class = '';
David Behler07b53422011-08-15 00:25:06 +020071 /**
72 * Current method name
73 *
74 * @var string
75 * @access public
76 */
Derek Allard2067d1a2008-11-13 22:59:24 +000077 var $method = 'index';
David Behler07b53422011-08-15 00:25:06 +020078 /**
79 * Sub-directory that contains the requested controller class
80 *
81 * @var string
82 * @access public
83 */
Derek Allard2067d1a2008-11-13 22:59:24 +000084 var $directory = '';
David Behler07b53422011-08-15 00:25:06 +020085 /**
86 * Default controller (and method if specific)
87 *
88 * @var string
89 * @access public
90 */
Derek Allard2067d1a2008-11-13 22:59:24 +000091 var $default_controller;
Barry Mienydd671972010-10-04 16:33:58 +020092
Derek Allard2067d1a2008-11-13 22:59:24 +000093 /**
94 * Constructor
95 *
96 * Runs the route mapping function.
97 */
Greg Akera9263282010-11-10 15:26:43 -060098 function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +000099 {
Derek Jonesc7738402010-03-02 13:55:13 -0600100 $this->config =& load_class('Config', 'core');
101 $this->uri =& load_class('URI', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 log_message('debug', "Router Class Initialized");
103 }
Barry Mienydd671972010-10-04 16:33:58 +0200104
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 /**
108 * Set the route mapping
109 *
110 * This function determines what should be served based on the URI request,
111 * as well as any "routes" that have been set in the routing config file.
112 *
113 * @access private
114 * @return void
115 */
116 function _set_routing()
Barry Mienydd671972010-10-04 16:33:58 +0200117 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500118 // Are query strings enabled in the config file? Normally CI doesn't utilize query strings
Barry Mienydd671972010-10-04 16:33:58 +0200119 // since URI segments are more search-engine friendly, but they can optionally be used.
Derek Jonesc7738402010-03-02 13:55:13 -0600120 // If this feature is enabled, we will gather the directory/class/method a little differently
121 $segments = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')]))
123 {
Derek Jonesc7738402010-03-02 13:55:13 -0600124 if (isset($_GET[$this->config->item('directory_trigger')]))
125 {
126 $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')])));
127 $segments[] = $this->fetch_directory();
128 }
Barry Mienydd671972010-10-04 16:33:58 +0200129
Derek Jonesc7738402010-03-02 13:55:13 -0600130 if (isset($_GET[$this->config->item('controller_trigger')]))
131 {
132 $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
133 $segments[] = $this->fetch_class();
134 }
Barry Mienydd671972010-10-04 16:33:58 +0200135
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 if (isset($_GET[$this->config->item('function_trigger')]))
137 {
138 $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
Derek Jonesc7738402010-03-02 13:55:13 -0600139 $segments[] = $this->fetch_method();
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 }
Barry Mienydd671972010-10-04 16:33:58 +0200142
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 // Load the routes.php file.
Greg Aker3a746652011-04-19 10:59:47 -0500144 if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
bubbafoley0ea04142011-03-17 14:55:41 -0500145 {
Greg Aker3a746652011-04-19 10:59:47 -0500146 include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
bubbafoley0ea04142011-03-17 14:55:41 -0500147 }
Greg Aker3a746652011-04-19 10:59:47 -0500148 elseif (is_file(APPPATH.'config/routes.php'))
bubbafoley0ea04142011-03-17 14:55:41 -0500149 {
Greg Aker3a746652011-04-19 10:59:47 -0500150 include(APPPATH.'config/routes.php');
bubbafoley0ea04142011-03-17 14:55:41 -0500151 }
David Behler07b53422011-08-15 00:25:06 +0200152
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
154 unset($route);
Barry Mienydd671972010-10-04 16:33:58 +0200155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 // Set the default controller so we can display it in the event
157 // the URI doesn't correlated to a valid controller.
Barry Mienydd671972010-10-04 16:33:58 +0200158 $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
159
Derek Jones37f4b9c2011-07-01 17:56:50 -0500160 // Were there any query string segments? If so, we'll validate them and bail out since we're done.
Derek Jonesc7738402010-03-02 13:55:13 -0600161 if (count($segments) > 0)
162 {
163 return $this->_validate_request($segments);
164 }
Barry Mienydd671972010-10-04 16:33:58 +0200165
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 // Fetch the complete URI string
167 $this->uri->_fetch_uri_string();
Barry Mienydd671972010-10-04 16:33:58 +0200168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 // Is there a URI string? If not, the default controller specified in the "routes" file will be shown.
170 if ($this->uri->uri_string == '')
171 {
Derek Jonesc7738402010-03-02 13:55:13 -0600172 return $this->_set_default_controller();
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 }
Barry Mienydd671972010-10-04 16:33:58 +0200174
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 // Do we need to remove the URL suffix?
176 $this->uri->_remove_url_suffix();
Barry Mienydd671972010-10-04 16:33:58 +0200177
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 // Compile the segments into an array
179 $this->uri->_explode_segments();
Barry Mienydd671972010-10-04 16:33:58 +0200180
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 // Parse any custom routing that may exist
Barry Mienydd671972010-10-04 16:33:58 +0200182 $this->_parse_routes();
183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 // Re-index the segment array so that it starts with 1 rather than 0
185 $this->uri->_reindex_segments();
186 }
Derek Jonesc7738402010-03-02 13:55:13 -0600187
188 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200189
Derek Jonesc7738402010-03-02 13:55:13 -0600190 /**
191 * Set the default controller
192 *
193 * @access private
194 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200195 */
Derek Jonesc7738402010-03-02 13:55:13 -0600196 function _set_default_controller()
197 {
198 if ($this->default_controller === FALSE)
199 {
200 show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
201 }
202 // Is the method being specified?
203 if (strpos($this->default_controller, '/') !== FALSE)
204 {
205 $x = explode('/', $this->default_controller);
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Jonesc7738402010-03-02 13:55:13 -0600207 $this->set_class($x[0]);
208 $this->set_method($x[1]);
Pascal Kriete790ebf32010-12-15 10:53:35 -0500209 $this->_set_request($x);
Barry Mienydd671972010-10-04 16:33:58 +0200210 }
Derek Jonesc7738402010-03-02 13:55:13 -0600211 else
212 {
213 $this->set_class($this->default_controller);
214 $this->set_method('index');
215 $this->_set_request(array($this->default_controller, 'index'));
216 }
Barry Mienydd671972010-10-04 16:33:58 +0200217
Derek Jonesc7738402010-03-02 13:55:13 -0600218 // re-index the routed segments array so it starts with 1 rather than 0
219 $this->uri->_reindex_segments();
Barry Mienydd671972010-10-04 16:33:58 +0200220
Derek Jonesc7738402010-03-02 13:55:13 -0600221 log_message('debug', "No URI present. Default controller set.");
222 }
Barry Mienydd671972010-10-04 16:33:58 +0200223
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 /**
227 * Set the Route
228 *
229 * This function takes an array of URI segments as
230 * input, and sets the current class/method
231 *
232 * @access private
233 * @param array
234 * @param bool
235 * @return void
236 */
237 function _set_request($segments = array())
Barry Mienydd671972010-10-04 16:33:58 +0200238 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 $segments = $this->_validate_request($segments);
Barry Mienydd671972010-10-04 16:33:58 +0200240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 if (count($segments) == 0)
242 {
Derek Jonesc7738402010-03-02 13:55:13 -0600243 return $this->_set_default_controller();
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 }
Barry Mienydd671972010-10-04 16:33:58 +0200245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 $this->set_class($segments[0]);
Barry Mienydd671972010-10-04 16:33:58 +0200247
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 if (isset($segments[1]))
249 {
Derek Jonesc7738402010-03-02 13:55:13 -0600250 // A standard method request
251 $this->set_method($segments[1]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 }
253 else
254 {
255 // This lets the "routed" segment array identify that the default
256 // index method is being used.
257 $segments[1] = 'index';
258 }
Barry Mienydd671972010-10-04 16:33:58 +0200259
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 // Update our "routed" segment array to contain the segments.
261 // Note: If there is no custom routing, this array will be
262 // identical to $this->uri->segments
263 $this->uri->rsegments = $segments;
264 }
Barry Mienydd671972010-10-04 16:33:58 +0200265
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200267
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500269 * Validates the supplied segments. Attempts to determine the path to
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 * the controller.
271 *
272 * @access private
273 * @param array
274 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200275 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 function _validate_request($segments)
277 {
Derek Jonesc7738402010-03-02 13:55:13 -0600278 if (count($segments) == 0)
279 {
280 return $segments;
281 }
Barry Mienydd671972010-10-04 16:33:58 +0200282
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 // Does the requested controller exist in the root folder?
Greg Aker3a746652011-04-19 10:59:47 -0500284 if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 {
286 return $segments;
287 }
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 // Is the controller in a sub-folder?
290 if (is_dir(APPPATH.'controllers/'.$segments[0]))
Derek Jonesc7738402010-03-02 13:55:13 -0600291 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 // Set the directory and remove it from the segment array
293 $this->set_directory($segments[0]);
294 $segments = array_slice($segments, 1);
Barry Mienydd671972010-10-04 16:33:58 +0200295
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 if (count($segments) > 0)
297 {
298 // Does the requested controller exist in the sub-folder?
Greg Aker3a746652011-04-19 10:59:47 -0500299 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 {
Shane Pearson664a9352011-08-10 16:02:32 -0500301 if ( ! empty($this->routes['404_override']))
302 {
303 $x = explode('/', $this->routes['404_override']);
304
305 $this->set_directory('');
306 $this->set_class($x[0]);
307 $this->set_method(isset($x[1]) ? $x[1] : 'index');
David Behler07b53422011-08-15 00:25:06 +0200308
Shane Pearson664a9352011-08-10 16:02:32 -0500309 return $x;
310 }
311 else
312 {
313 show_404($this->fetch_directory().$segments[0]);
314 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 }
316 }
317 else
318 {
Derek Jonesc7738402010-03-02 13:55:13 -0600319 // Is the method being specified in the route?
320 if (strpos($this->default_controller, '/') !== FALSE)
321 {
322 $x = explode('/', $this->default_controller);
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Jonesc7738402010-03-02 13:55:13 -0600324 $this->set_class($x[0]);
325 $this->set_method($x[1]);
Barry Mienydd671972010-10-04 16:33:58 +0200326 }
Derek Jonesc7738402010-03-02 13:55:13 -0600327 else
328 {
329 $this->set_class($this->default_controller);
330 $this->set_method('index');
331 }
Barry Mienydd671972010-10-04 16:33:58 +0200332
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 // Does the default controller exist in the sub-folder?
Greg Aker3a746652011-04-19 10:59:47 -0500334 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 {
336 $this->directory = '';
337 return array();
338 }
Barry Mienydd671972010-10-04 16:33:58 +0200339
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 }
Barry Mienydd671972010-10-04 16:33:58 +0200341
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 return $segments;
343 }
Barry Mienydd671972010-10-04 16:33:58 +0200344
345
Derek Jonesc7738402010-03-02 13:55:13 -0600346 // If we've gotten this far it means that the URI does not correlate to a valid
Derek Jones37f4b9c2011-07-01 17:56:50 -0500347 // controller class. We will now see if there is an override
Eric Barnesc5bf6162011-01-30 21:17:11 -0500348 if ( ! empty($this->routes['404_override']))
Derek Jonesc7738402010-03-02 13:55:13 -0600349 {
Phil Sturgeon23174a62010-12-15 15:18:16 +0000350 $x = explode('/', $this->routes['404_override']);
Barry Mienydd671972010-10-04 16:33:58 +0200351
Phil Sturgeon23174a62010-12-15 15:18:16 +0000352 $this->set_class($x[0]);
353 $this->set_method(isset($x[1]) ? $x[1] : 'index');
Barry Mienydd671972010-10-04 16:33:58 +0200354
Phil Sturgeon23174a62010-12-15 15:18:16 +0000355 return $x;
Derek Jonesc7738402010-03-02 13:55:13 -0600356 }
Barry Mienydd671972010-10-04 16:33:58 +0200357
Phil Sturgeon23174a62010-12-15 15:18:16 +0000358
Derek Jonesc7738402010-03-02 13:55:13 -0600359 // Nothing else to do at this point but show a 404
Barry Mienydd671972010-10-04 16:33:58 +0200360 show_404($segments[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 }
Barry Mienydd671972010-10-04 16:33:58 +0200362
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200364
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500366 * Parse Routes
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 *
368 * This function matches any routes that may exist in
369 * the config/routes.php file against the URI to
370 * determine if the class/method need to be remapped.
371 *
372 * @access private
373 * @return void
374 */
375 function _parse_routes()
376 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 // Turn the segment array into a URI string
378 $uri = implode('/', $this->uri->segments);
Barry Mienydd671972010-10-04 16:33:58 +0200379
Derek Jones37f4b9c2011-07-01 17:56:50 -0500380 // Is there a literal match? If so we're done
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 if (isset($this->routes[$uri]))
382 {
Derek Jonesc7738402010-03-02 13:55:13 -0600383 return $this->_set_request(explode('/', $this->routes[$uri]));
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 }
Barry Mienydd671972010-10-04 16:33:58 +0200385
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 // Loop through the route array looking for wild-cards
387 foreach ($this->routes as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200388 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 // Convert wild-cards to RegEx
390 $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
Derek Jonesc7738402010-03-02 13:55:13 -0600391
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 // Does the RegEx match?
393 if (preg_match('#^'.$key.'$#', $uri))
Derek Jonesc7738402010-03-02 13:55:13 -0600394 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 // Do we have a back-reference?
396 if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE)
397 {
398 $val = preg_replace('#^'.$key.'$#', $val, $uri);
399 }
Barry Mienydd671972010-10-04 16:33:58 +0200400
401 return $this->_set_request(explode('/', $val));
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 }
403 }
404
405 // If we got this far it means we didn't encounter a
406 // matching route so we'll set the site default route
407 $this->_set_request($this->uri->segments);
408 }
409
410 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 /**
413 * Set the class name
414 *
415 * @access public
416 * @param string
417 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200418 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 function set_class($class)
420 {
Derek Jones2615e412010-10-06 17:51:16 -0500421 $this->class = str_replace(array('/', '.'), '', $class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 }
Barry Mienydd671972010-10-04 16:33:58 +0200423
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200425
Derek Allard2067d1a2008-11-13 22:59:24 +0000426 /**
427 * Fetch the current class
428 *
429 * @access public
430 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200431 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 function fetch_class()
433 {
434 return $this->class;
435 }
Barry Mienydd671972010-10-04 16:33:58 +0200436
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200438
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500440 * Set the method name
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 *
442 * @access public
443 * @param string
444 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200445 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 function set_method($method)
447 {
448 $this->method = $method;
449 }
450
451 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200452
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500454 * Fetch the current method
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 *
456 * @access public
457 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200458 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 function fetch_method()
460 {
461 if ($this->method == $this->fetch_class())
462 {
463 return 'index';
464 }
465
466 return $this->method;
467 }
468
469 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200470
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500472 * Set the directory name
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 *
474 * @access public
475 * @param string
476 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200477 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 function set_directory($dir)
479 {
Derek Jones2615e412010-10-06 17:51:16 -0500480 $this->directory = str_replace(array('/', '.'), '', $dir).'/';
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 }
482
483 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200484
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500486 * Fetch the sub-directory (if any) that contains the requested controller class
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 *
488 * @access public
489 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200490 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 function fetch_directory()
492 {
493 return $this->directory;
494 }
495
Derek Jonesc7738402010-03-02 13:55:13 -0600496 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200497
Derek Jonesc7738402010-03-02 13:55:13 -0600498 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500499 * Set the controller overrides
Derek Jonesc7738402010-03-02 13:55:13 -0600500 *
501 * @access public
502 * @param array
503 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200504 */
Derek Jonesc7738402010-03-02 13:55:13 -0600505 function _set_overrides($routing)
506 {
507 if ( ! is_array($routing))
508 {
509 return;
510 }
Barry Mienydd671972010-10-04 16:33:58 +0200511
Derek Jonesc7738402010-03-02 13:55:13 -0600512 if (isset($routing['directory']))
513 {
514 $this->set_directory($routing['directory']);
515 }
Barry Mienydd671972010-10-04 16:33:58 +0200516
Derek Jonesc7738402010-03-02 13:55:13 -0600517 if (isset($routing['controller']) AND $routing['controller'] != '')
518 {
519 $this->set_class($routing['controller']);
520 }
Barry Mienydd671972010-10-04 16:33:58 +0200521
Derek Jonesc7738402010-03-02 13:55:13 -0600522 if (isset($routing['function']))
523 {
524 $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
525 $this->set_method($routing['function']);
526 }
527 }
528
529
Derek Allard2067d1a2008-11-13 22:59:24 +0000530}
531// END Router Class
532
533/* End of file Router.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600534/* Location: ./system/core/Router.php */