blob: 5388a9289852df124422d594468a2de3791a6de1 [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 Aker5c1aa632011-12-25 01:24:29 -0600144 load_environ_config('routes');
David Behler07b53422011-08-15 00:25:06 +0200145
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
147 unset($route);
Barry Mienydd671972010-10-04 16:33:58 +0200148
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 // Set the default controller so we can display it in the event
150 // the URI doesn't correlated to a valid controller.
Barry Mienydd671972010-10-04 16:33:58 +0200151 $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
152
Derek Jones37f4b9c2011-07-01 17:56:50 -0500153 // 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 -0600154 if (count($segments) > 0)
155 {
156 return $this->_validate_request($segments);
157 }
Barry Mienydd671972010-10-04 16:33:58 +0200158
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 // Fetch the complete URI string
160 $this->uri->_fetch_uri_string();
Barry Mienydd671972010-10-04 16:33:58 +0200161
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 // Is there a URI string? If not, the default controller specified in the "routes" file will be shown.
163 if ($this->uri->uri_string == '')
164 {
Derek Jonesc7738402010-03-02 13:55:13 -0600165 return $this->_set_default_controller();
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 }
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 // Do we need to remove the URL suffix?
169 $this->uri->_remove_url_suffix();
Barry Mienydd671972010-10-04 16:33:58 +0200170
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 // Compile the segments into an array
172 $this->uri->_explode_segments();
Barry Mienydd671972010-10-04 16:33:58 +0200173
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 // Parse any custom routing that may exist
Barry Mienydd671972010-10-04 16:33:58 +0200175 $this->_parse_routes();
176
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 // Re-index the segment array so that it starts with 1 rather than 0
178 $this->uri->_reindex_segments();
179 }
Derek Jonesc7738402010-03-02 13:55:13 -0600180
181 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200182
Derek Jonesc7738402010-03-02 13:55:13 -0600183 /**
184 * Set the default controller
185 *
186 * @access private
187 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200188 */
Derek Jonesc7738402010-03-02 13:55:13 -0600189 function _set_default_controller()
190 {
191 if ($this->default_controller === FALSE)
192 {
193 show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
194 }
195 // Is the method being specified?
196 if (strpos($this->default_controller, '/') !== FALSE)
197 {
198 $x = explode('/', $this->default_controller);
Barry Mienydd671972010-10-04 16:33:58 +0200199
Derek Jonesc7738402010-03-02 13:55:13 -0600200 $this->set_class($x[0]);
201 $this->set_method($x[1]);
Pascal Kriete790ebf32010-12-15 10:53:35 -0500202 $this->_set_request($x);
Barry Mienydd671972010-10-04 16:33:58 +0200203 }
Derek Jonesc7738402010-03-02 13:55:13 -0600204 else
205 {
206 $this->set_class($this->default_controller);
207 $this->set_method('index');
208 $this->_set_request(array($this->default_controller, 'index'));
209 }
Barry Mienydd671972010-10-04 16:33:58 +0200210
Derek Jonesc7738402010-03-02 13:55:13 -0600211 // re-index the routed segments array so it starts with 1 rather than 0
212 $this->uri->_reindex_segments();
Barry Mienydd671972010-10-04 16:33:58 +0200213
Derek Jonesc7738402010-03-02 13:55:13 -0600214 log_message('debug', "No URI present. Default controller set.");
215 }
Barry Mienydd671972010-10-04 16:33:58 +0200216
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 /**
220 * Set the Route
221 *
222 * This function takes an array of URI segments as
223 * input, and sets the current class/method
224 *
225 * @access private
226 * @param array
227 * @param bool
228 * @return void
229 */
230 function _set_request($segments = array())
Barry Mienydd671972010-10-04 16:33:58 +0200231 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 $segments = $this->_validate_request($segments);
Barry Mienydd671972010-10-04 16:33:58 +0200233
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 if (count($segments) == 0)
235 {
Derek Jonesc7738402010-03-02 13:55:13 -0600236 return $this->_set_default_controller();
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 }
Barry Mienydd671972010-10-04 16:33:58 +0200238
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 $this->set_class($segments[0]);
Barry Mienydd671972010-10-04 16:33:58 +0200240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 if (isset($segments[1]))
242 {
Derek Jonesc7738402010-03-02 13:55:13 -0600243 // A standard method request
244 $this->set_method($segments[1]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 }
246 else
247 {
248 // This lets the "routed" segment array identify that the default
249 // index method is being used.
250 $segments[1] = 'index';
251 }
Barry Mienydd671972010-10-04 16:33:58 +0200252
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 // Update our "routed" segment array to contain the segments.
254 // Note: If there is no custom routing, this array will be
255 // identical to $this->uri->segments
256 $this->uri->rsegments = $segments;
257 }
Barry Mienydd671972010-10-04 16:33:58 +0200258
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200260
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500262 * Validates the supplied segments. Attempts to determine the path to
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 * the controller.
264 *
265 * @access private
266 * @param array
267 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200268 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 function _validate_request($segments)
270 {
Derek Jonesc7738402010-03-02 13:55:13 -0600271 if (count($segments) == 0)
272 {
273 return $segments;
274 }
Barry Mienydd671972010-10-04 16:33:58 +0200275
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 // Does the requested controller exist in the root folder?
Greg Aker3a746652011-04-19 10:59:47 -0500277 if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 {
279 return $segments;
280 }
Barry Mienydd671972010-10-04 16:33:58 +0200281
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 // Is the controller in a sub-folder?
283 if (is_dir(APPPATH.'controllers/'.$segments[0]))
Derek Jonesc7738402010-03-02 13:55:13 -0600284 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 // Set the directory and remove it from the segment array
286 $this->set_directory($segments[0]);
287 $segments = array_slice($segments, 1);
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 if (count($segments) > 0)
290 {
291 // Does the requested controller exist in the sub-folder?
Greg Aker3a746652011-04-19 10:59:47 -0500292 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 {
Shane Pearson664a9352011-08-10 16:02:32 -0500294 if ( ! empty($this->routes['404_override']))
295 {
296 $x = explode('/', $this->routes['404_override']);
297
298 $this->set_directory('');
299 $this->set_class($x[0]);
300 $this->set_method(isset($x[1]) ? $x[1] : 'index');
David Behler07b53422011-08-15 00:25:06 +0200301
Shane Pearson664a9352011-08-10 16:02:32 -0500302 return $x;
303 }
304 else
305 {
306 show_404($this->fetch_directory().$segments[0]);
307 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 }
309 }
310 else
311 {
Derek Jonesc7738402010-03-02 13:55:13 -0600312 // Is the method being specified in the route?
313 if (strpos($this->default_controller, '/') !== FALSE)
314 {
315 $x = explode('/', $this->default_controller);
Barry Mienydd671972010-10-04 16:33:58 +0200316
Derek Jonesc7738402010-03-02 13:55:13 -0600317 $this->set_class($x[0]);
318 $this->set_method($x[1]);
Barry Mienydd671972010-10-04 16:33:58 +0200319 }
Derek Jonesc7738402010-03-02 13:55:13 -0600320 else
321 {
322 $this->set_class($this->default_controller);
323 $this->set_method('index');
324 }
Barry Mienydd671972010-10-04 16:33:58 +0200325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 // Does the default controller exist in the sub-folder?
Greg Aker3a746652011-04-19 10:59:47 -0500327 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 {
329 $this->directory = '';
330 return array();
331 }
Barry Mienydd671972010-10-04 16:33:58 +0200332
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 }
Barry Mienydd671972010-10-04 16:33:58 +0200334
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 return $segments;
336 }
Barry Mienydd671972010-10-04 16:33:58 +0200337
338
Derek Jonesc7738402010-03-02 13:55:13 -0600339 // If we've gotten this far it means that the URI does not correlate to a valid
Derek Jones37f4b9c2011-07-01 17:56:50 -0500340 // controller class. We will now see if there is an override
Eric Barnesc5bf6162011-01-30 21:17:11 -0500341 if ( ! empty($this->routes['404_override']))
Derek Jonesc7738402010-03-02 13:55:13 -0600342 {
Phil Sturgeon23174a62010-12-15 15:18:16 +0000343 $x = explode('/', $this->routes['404_override']);
Barry Mienydd671972010-10-04 16:33:58 +0200344
Phil Sturgeon23174a62010-12-15 15:18:16 +0000345 $this->set_class($x[0]);
346 $this->set_method(isset($x[1]) ? $x[1] : 'index');
Barry Mienydd671972010-10-04 16:33:58 +0200347
Phil Sturgeon23174a62010-12-15 15:18:16 +0000348 return $x;
Derek Jonesc7738402010-03-02 13:55:13 -0600349 }
Barry Mienydd671972010-10-04 16:33:58 +0200350
Phil Sturgeon23174a62010-12-15 15:18:16 +0000351
Derek Jonesc7738402010-03-02 13:55:13 -0600352 // Nothing else to do at this point but show a 404
Barry Mienydd671972010-10-04 16:33:58 +0200353 show_404($segments[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 }
Barry Mienydd671972010-10-04 16:33:58 +0200355
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200357
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500359 * Parse Routes
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 *
361 * This function matches any routes that may exist in
362 * the config/routes.php file against the URI to
363 * determine if the class/method need to be remapped.
364 *
365 * @access private
366 * @return void
367 */
368 function _parse_routes()
369 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 // Turn the segment array into a URI string
371 $uri = implode('/', $this->uri->segments);
Barry Mienydd671972010-10-04 16:33:58 +0200372
Derek Jones37f4b9c2011-07-01 17:56:50 -0500373 // Is there a literal match? If so we're done
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 if (isset($this->routes[$uri]))
375 {
Derek Jonesc7738402010-03-02 13:55:13 -0600376 return $this->_set_request(explode('/', $this->routes[$uri]));
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 }
Barry Mienydd671972010-10-04 16:33:58 +0200378
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 // Loop through the route array looking for wild-cards
380 foreach ($this->routes as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200381 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 // Convert wild-cards to RegEx
383 $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
Derek Jonesc7738402010-03-02 13:55:13 -0600384
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 // Does the RegEx match?
386 if (preg_match('#^'.$key.'$#', $uri))
Derek Jonesc7738402010-03-02 13:55:13 -0600387 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 // Do we have a back-reference?
389 if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE)
390 {
391 $val = preg_replace('#^'.$key.'$#', $val, $uri);
392 }
Barry Mienydd671972010-10-04 16:33:58 +0200393
394 return $this->_set_request(explode('/', $val));
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 }
396 }
397
398 // If we got this far it means we didn't encounter a
399 // matching route so we'll set the site default route
400 $this->_set_request($this->uri->segments);
401 }
402
403 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200404
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 /**
406 * Set the class name
407 *
408 * @access public
409 * @param string
410 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200411 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 function set_class($class)
413 {
Derek Jones2615e412010-10-06 17:51:16 -0500414 $this->class = str_replace(array('/', '.'), '', $class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 }
Barry Mienydd671972010-10-04 16:33:58 +0200416
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200418
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 /**
420 * Fetch the current class
421 *
422 * @access public
423 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200424 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 function fetch_class()
426 {
427 return $this->class;
428 }
Barry Mienydd671972010-10-04 16:33:58 +0200429
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200431
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500433 * Set the method name
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 *
435 * @access public
436 * @param string
437 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200438 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 function set_method($method)
440 {
441 $this->method = $method;
442 }
443
444 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500447 * Fetch the current method
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 *
449 * @access public
450 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200451 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 function fetch_method()
453 {
454 if ($this->method == $this->fetch_class())
455 {
456 return 'index';
457 }
458
459 return $this->method;
460 }
461
462 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200463
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500465 * Set the directory name
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 *
467 * @access public
468 * @param string
469 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200470 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 function set_directory($dir)
472 {
Derek Jones2615e412010-10-06 17:51:16 -0500473 $this->directory = str_replace(array('/', '.'), '', $dir).'/';
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 }
475
476 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200477
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500479 * Fetch the sub-directory (if any) that contains the requested controller class
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 *
481 * @access public
482 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200483 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 function fetch_directory()
485 {
486 return $this->directory;
487 }
488
Derek Jonesc7738402010-03-02 13:55:13 -0600489 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200490
Derek Jonesc7738402010-03-02 13:55:13 -0600491 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500492 * Set the controller overrides
Derek Jonesc7738402010-03-02 13:55:13 -0600493 *
494 * @access public
495 * @param array
496 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200497 */
Derek Jonesc7738402010-03-02 13:55:13 -0600498 function _set_overrides($routing)
499 {
500 if ( ! is_array($routing))
501 {
502 return;
503 }
Barry Mienydd671972010-10-04 16:33:58 +0200504
Derek Jonesc7738402010-03-02 13:55:13 -0600505 if (isset($routing['directory']))
506 {
507 $this->set_directory($routing['directory']);
508 }
Barry Mienydd671972010-10-04 16:33:58 +0200509
Derek Jonesc7738402010-03-02 13:55:13 -0600510 if (isset($routing['controller']) AND $routing['controller'] != '')
511 {
512 $this->set_class($routing['controller']);
513 }
Barry Mienydd671972010-10-04 16:33:58 +0200514
Derek Jonesc7738402010-03-02 13:55:13 -0600515 if (isset($routing['function']))
516 {
517 $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
518 $this->set_method($routing['function']);
519 }
520 }
521
522
Derek Allard2067d1a2008-11-13 22:59:24 +0000523}
524// END Router Class
525
526/* End of file Router.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600527/* Location: ./system/core/Router.php */