blob: 6da66747267695ad1b4ebfec2cffba6d19c9ae4c [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 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Router Class
20 *
21 * Parses URIs and determines routing
22 *
23 * @package CodeIgniter
24 * @subpackage Libraries
25 * @author ExpressionEngine Dev Team
26 * @category Libraries
27 * @link http://codeigniter.com/user_guide/general/routing.html
28 */
29class CI_Router {
30
David Behler07b53422011-08-15 00:25:06 +020031 /**
32 * Config class
33 *
34 * @var object
35 * @access public
36 */
Barry Mienydd671972010-10-04 16:33:58 +020037 var $config;
David Behler07b53422011-08-15 00:25:06 +020038 /**
39 * List of routes
40 *
41 * @var array
42 * @access public
43 */
Barry Mienydd671972010-10-04 16:33:58 +020044 var $routes = array();
David Behler07b53422011-08-15 00:25:06 +020045 /**
46 * List of error routes
47 *
48 * @var array
49 * @access public
50 */
Derek Allard2067d1a2008-11-13 22:59:24 +000051 var $error_routes = array();
David Behler07b53422011-08-15 00:25:06 +020052 /**
53 * Current class name
54 *
55 * @var string
56 * @access public
57 */
Derek Allard2067d1a2008-11-13 22:59:24 +000058 var $class = '';
David Behler07b53422011-08-15 00:25:06 +020059 /**
60 * Current method name
61 *
62 * @var string
63 * @access public
64 */
Derek Allard2067d1a2008-11-13 22:59:24 +000065 var $method = 'index';
David Behler07b53422011-08-15 00:25:06 +020066 /**
67 * Sub-directory that contains the requested controller class
68 *
69 * @var string
70 * @access public
71 */
Derek Allard2067d1a2008-11-13 22:59:24 +000072 var $directory = '';
David Behler07b53422011-08-15 00:25:06 +020073 /**
74 * Default controller (and method if specific)
75 *
76 * @var string
77 * @access public
78 */
Derek Allard2067d1a2008-11-13 22:59:24 +000079 var $default_controller;
Barry Mienydd671972010-10-04 16:33:58 +020080
Derek Allard2067d1a2008-11-13 22:59:24 +000081 /**
82 * Constructor
83 *
84 * Runs the route mapping function.
85 */
Greg Akera9263282010-11-10 15:26:43 -060086 function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +000087 {
Derek Jonesc7738402010-03-02 13:55:13 -060088 $this->config =& load_class('Config', 'core');
89 $this->uri =& load_class('URI', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +000090 log_message('debug', "Router Class Initialized");
91 }
Barry Mienydd671972010-10-04 16:33:58 +020092
Derek Allard2067d1a2008-11-13 22:59:24 +000093 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020094
Derek Allard2067d1a2008-11-13 22:59:24 +000095 /**
96 * Set the route mapping
97 *
98 * This function determines what should be served based on the URI request,
99 * as well as any "routes" that have been set in the routing config file.
100 *
101 * @access private
102 * @return void
103 */
104 function _set_routing()
Barry Mienydd671972010-10-04 16:33:58 +0200105 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500106 // Are query strings enabled in the config file? Normally CI doesn't utilize query strings
Barry Mienydd671972010-10-04 16:33:58 +0200107 // since URI segments are more search-engine friendly, but they can optionally be used.
Derek Jonesc7738402010-03-02 13:55:13 -0600108 // If this feature is enabled, we will gather the directory/class/method a little differently
109 $segments = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')]))
111 {
Derek Jonesc7738402010-03-02 13:55:13 -0600112 if (isset($_GET[$this->config->item('directory_trigger')]))
113 {
114 $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')])));
115 $segments[] = $this->fetch_directory();
116 }
Barry Mienydd671972010-10-04 16:33:58 +0200117
Derek Jonesc7738402010-03-02 13:55:13 -0600118 if (isset($_GET[$this->config->item('controller_trigger')]))
119 {
120 $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
121 $segments[] = $this->fetch_class();
122 }
Barry Mienydd671972010-10-04 16:33:58 +0200123
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 if (isset($_GET[$this->config->item('function_trigger')]))
125 {
126 $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
Derek Jonesc7738402010-03-02 13:55:13 -0600127 $segments[] = $this->fetch_method();
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 }
Barry Mienydd671972010-10-04 16:33:58 +0200130
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 // Load the routes.php file.
Greg Aker3a746652011-04-19 10:59:47 -0500132 if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
bubbafoley0ea04142011-03-17 14:55:41 -0500133 {
Greg Aker3a746652011-04-19 10:59:47 -0500134 include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
bubbafoley0ea04142011-03-17 14:55:41 -0500135 }
Greg Aker3a746652011-04-19 10:59:47 -0500136 elseif (is_file(APPPATH.'config/routes.php'))
bubbafoley0ea04142011-03-17 14:55:41 -0500137 {
Greg Aker3a746652011-04-19 10:59:47 -0500138 include(APPPATH.'config/routes.php');
bubbafoley0ea04142011-03-17 14:55:41 -0500139 }
David Behler07b53422011-08-15 00:25:06 +0200140
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
142 unset($route);
Barry Mienydd671972010-10-04 16:33:58 +0200143
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 // Set the default controller so we can display it in the event
145 // the URI doesn't correlated to a valid controller.
Barry Mienydd671972010-10-04 16:33:58 +0200146 $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
147
Derek Jones37f4b9c2011-07-01 17:56:50 -0500148 // 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 -0600149 if (count($segments) > 0)
150 {
151 return $this->_validate_request($segments);
152 }
Barry Mienydd671972010-10-04 16:33:58 +0200153
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 // Fetch the complete URI string
155 $this->uri->_fetch_uri_string();
Barry Mienydd671972010-10-04 16:33:58 +0200156
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 // Is there a URI string? If not, the default controller specified in the "routes" file will be shown.
158 if ($this->uri->uri_string == '')
159 {
Derek Jonesc7738402010-03-02 13:55:13 -0600160 return $this->_set_default_controller();
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 }
Barry Mienydd671972010-10-04 16:33:58 +0200162
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 // Do we need to remove the URL suffix?
164 $this->uri->_remove_url_suffix();
Barry Mienydd671972010-10-04 16:33:58 +0200165
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 // Compile the segments into an array
167 $this->uri->_explode_segments();
Barry Mienydd671972010-10-04 16:33:58 +0200168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 // Parse any custom routing that may exist
Barry Mienydd671972010-10-04 16:33:58 +0200170 $this->_parse_routes();
171
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 // Re-index the segment array so that it starts with 1 rather than 0
173 $this->uri->_reindex_segments();
174 }
Derek Jonesc7738402010-03-02 13:55:13 -0600175
176 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200177
Derek Jonesc7738402010-03-02 13:55:13 -0600178 /**
179 * Set the default controller
180 *
181 * @access private
182 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200183 */
Derek Jonesc7738402010-03-02 13:55:13 -0600184 function _set_default_controller()
185 {
186 if ($this->default_controller === FALSE)
187 {
188 show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
189 }
190 // Is the method being specified?
191 if (strpos($this->default_controller, '/') !== FALSE)
192 {
193 $x = explode('/', $this->default_controller);
Barry Mienydd671972010-10-04 16:33:58 +0200194
Derek Jonesc7738402010-03-02 13:55:13 -0600195 $this->set_class($x[0]);
196 $this->set_method($x[1]);
Pascal Kriete790ebf32010-12-15 10:53:35 -0500197 $this->_set_request($x);
Barry Mienydd671972010-10-04 16:33:58 +0200198 }
Derek Jonesc7738402010-03-02 13:55:13 -0600199 else
200 {
201 $this->set_class($this->default_controller);
202 $this->set_method('index');
203 $this->_set_request(array($this->default_controller, 'index'));
204 }
Barry Mienydd671972010-10-04 16:33:58 +0200205
Derek Jonesc7738402010-03-02 13:55:13 -0600206 // re-index the routed segments array so it starts with 1 rather than 0
207 $this->uri->_reindex_segments();
Barry Mienydd671972010-10-04 16:33:58 +0200208
Derek Jonesc7738402010-03-02 13:55:13 -0600209 log_message('debug', "No URI present. Default controller set.");
210 }
Barry Mienydd671972010-10-04 16:33:58 +0200211
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200213
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 /**
215 * Set the Route
216 *
217 * This function takes an array of URI segments as
218 * input, and sets the current class/method
219 *
220 * @access private
221 * @param array
222 * @param bool
223 * @return void
224 */
225 function _set_request($segments = array())
Barry Mienydd671972010-10-04 16:33:58 +0200226 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 $segments = $this->_validate_request($segments);
Barry Mienydd671972010-10-04 16:33:58 +0200228
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 if (count($segments) == 0)
230 {
Derek Jonesc7738402010-03-02 13:55:13 -0600231 return $this->_set_default_controller();
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 }
Barry Mienydd671972010-10-04 16:33:58 +0200233
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 $this->set_class($segments[0]);
Barry Mienydd671972010-10-04 16:33:58 +0200235
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 if (isset($segments[1]))
237 {
Derek Jonesc7738402010-03-02 13:55:13 -0600238 // A standard method request
239 $this->set_method($segments[1]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 }
241 else
242 {
243 // This lets the "routed" segment array identify that the default
244 // index method is being used.
245 $segments[1] = 'index';
246 }
Barry Mienydd671972010-10-04 16:33:58 +0200247
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 // Update our "routed" segment array to contain the segments.
249 // Note: If there is no custom routing, this array will be
250 // identical to $this->uri->segments
251 $this->uri->rsegments = $segments;
252 }
Barry Mienydd671972010-10-04 16:33:58 +0200253
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200255
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500257 * Validates the supplied segments. Attempts to determine the path to
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 * the controller.
259 *
260 * @access private
261 * @param array
262 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200263 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 function _validate_request($segments)
265 {
Derek Jonesc7738402010-03-02 13:55:13 -0600266 if (count($segments) == 0)
267 {
268 return $segments;
269 }
Barry Mienydd671972010-10-04 16:33:58 +0200270
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 // Does the requested controller exist in the root folder?
Greg Aker3a746652011-04-19 10:59:47 -0500272 if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 {
274 return $segments;
275 }
Barry Mienydd671972010-10-04 16:33:58 +0200276
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 // Is the controller in a sub-folder?
278 if (is_dir(APPPATH.'controllers/'.$segments[0]))
Derek Jonesc7738402010-03-02 13:55:13 -0600279 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 // Set the directory and remove it from the segment array
281 $this->set_directory($segments[0]);
282 $segments = array_slice($segments, 1);
Barry Mienydd671972010-10-04 16:33:58 +0200283
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 if (count($segments) > 0)
285 {
286 // Does the requested controller exist in the sub-folder?
Greg Aker3a746652011-04-19 10:59:47 -0500287 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 {
Shane Pearson664a9352011-08-10 16:02:32 -0500289 if ( ! empty($this->routes['404_override']))
290 {
291 $x = explode('/', $this->routes['404_override']);
292
293 $this->set_directory('');
294 $this->set_class($x[0]);
295 $this->set_method(isset($x[1]) ? $x[1] : 'index');
David Behler07b53422011-08-15 00:25:06 +0200296
Shane Pearson664a9352011-08-10 16:02:32 -0500297 return $x;
298 }
299 else
300 {
301 show_404($this->fetch_directory().$segments[0]);
302 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 }
304 }
305 else
306 {
Derek Jonesc7738402010-03-02 13:55:13 -0600307 // Is the method being specified in the route?
308 if (strpos($this->default_controller, '/') !== FALSE)
309 {
310 $x = explode('/', $this->default_controller);
Barry Mienydd671972010-10-04 16:33:58 +0200311
Derek Jonesc7738402010-03-02 13:55:13 -0600312 $this->set_class($x[0]);
313 $this->set_method($x[1]);
Barry Mienydd671972010-10-04 16:33:58 +0200314 }
Derek Jonesc7738402010-03-02 13:55:13 -0600315 else
316 {
317 $this->set_class($this->default_controller);
318 $this->set_method('index');
319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 // Does the default controller exist in the sub-folder?
Greg Aker3a746652011-04-19 10:59:47 -0500322 if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 {
324 $this->directory = '';
325 return array();
326 }
Barry Mienydd671972010-10-04 16:33:58 +0200327
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 }
Barry Mienydd671972010-10-04 16:33:58 +0200329
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 return $segments;
331 }
Barry Mienydd671972010-10-04 16:33:58 +0200332
333
Derek Jonesc7738402010-03-02 13:55:13 -0600334 // If we've gotten this far it means that the URI does not correlate to a valid
Derek Jones37f4b9c2011-07-01 17:56:50 -0500335 // controller class. We will now see if there is an override
Eric Barnesc5bf6162011-01-30 21:17:11 -0500336 if ( ! empty($this->routes['404_override']))
Derek Jonesc7738402010-03-02 13:55:13 -0600337 {
Phil Sturgeon23174a62010-12-15 15:18:16 +0000338 $x = explode('/', $this->routes['404_override']);
Barry Mienydd671972010-10-04 16:33:58 +0200339
Phil Sturgeon23174a62010-12-15 15:18:16 +0000340 $this->set_class($x[0]);
341 $this->set_method(isset($x[1]) ? $x[1] : 'index');
Barry Mienydd671972010-10-04 16:33:58 +0200342
Phil Sturgeon23174a62010-12-15 15:18:16 +0000343 return $x;
Derek Jonesc7738402010-03-02 13:55:13 -0600344 }
Barry Mienydd671972010-10-04 16:33:58 +0200345
Phil Sturgeon23174a62010-12-15 15:18:16 +0000346
Derek Jonesc7738402010-03-02 13:55:13 -0600347 // Nothing else to do at this point but show a 404
Barry Mienydd671972010-10-04 16:33:58 +0200348 show_404($segments[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 }
Barry Mienydd671972010-10-04 16:33:58 +0200350
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200352
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500354 * Parse Routes
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 *
356 * This function matches any routes that may exist in
357 * the config/routes.php file against the URI to
358 * determine if the class/method need to be remapped.
359 *
360 * @access private
361 * @return void
362 */
363 function _parse_routes()
364 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 // Turn the segment array into a URI string
366 $uri = implode('/', $this->uri->segments);
Barry Mienydd671972010-10-04 16:33:58 +0200367
Derek Jones37f4b9c2011-07-01 17:56:50 -0500368 // Is there a literal match? If so we're done
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 if (isset($this->routes[$uri]))
370 {
Derek Jonesc7738402010-03-02 13:55:13 -0600371 return $this->_set_request(explode('/', $this->routes[$uri]));
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 }
Barry Mienydd671972010-10-04 16:33:58 +0200373
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 // Loop through the route array looking for wild-cards
375 foreach ($this->routes as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200376 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 // Convert wild-cards to RegEx
378 $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
Derek Jonesc7738402010-03-02 13:55:13 -0600379
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 // Does the RegEx match?
381 if (preg_match('#^'.$key.'$#', $uri))
Derek Jonesc7738402010-03-02 13:55:13 -0600382 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 // Do we have a back-reference?
384 if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE)
385 {
386 $val = preg_replace('#^'.$key.'$#', $val, $uri);
387 }
Barry Mienydd671972010-10-04 16:33:58 +0200388
389 return $this->_set_request(explode('/', $val));
Derek Allard2067d1a2008-11-13 22:59:24 +0000390 }
391 }
392
393 // If we got this far it means we didn't encounter a
394 // matching route so we'll set the site default route
395 $this->_set_request($this->uri->segments);
396 }
397
398 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200399
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 /**
401 * Set the class name
402 *
403 * @access public
404 * @param string
405 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200406 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 function set_class($class)
408 {
Derek Jones2615e412010-10-06 17:51:16 -0500409 $this->class = str_replace(array('/', '.'), '', $class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 }
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200413
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 /**
415 * Fetch the current class
416 *
417 * @access public
418 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200419 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 function fetch_class()
421 {
422 return $this->class;
423 }
Barry Mienydd671972010-10-04 16:33:58 +0200424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200426
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500428 * Set the method name
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 *
430 * @access public
431 * @param string
432 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200433 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 function set_method($method)
435 {
436 $this->method = $method;
437 }
438
439 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200440
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500442 * Fetch the current method
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 *
444 * @access public
445 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200446 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 function fetch_method()
448 {
449 if ($this->method == $this->fetch_class())
450 {
451 return 'index';
452 }
453
454 return $this->method;
455 }
456
457 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200458
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500460 * Set the directory name
Derek Allard2067d1a2008-11-13 22:59:24 +0000461 *
462 * @access public
463 * @param string
464 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200465 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 function set_directory($dir)
467 {
Derek Jones2615e412010-10-06 17:51:16 -0500468 $this->directory = str_replace(array('/', '.'), '', $dir).'/';
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 }
470
471 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200472
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500474 * Fetch the sub-directory (if any) that contains the requested controller class
Derek Allard2067d1a2008-11-13 22:59:24 +0000475 *
476 * @access public
477 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200478 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 function fetch_directory()
480 {
481 return $this->directory;
482 }
483
Derek Jonesc7738402010-03-02 13:55:13 -0600484 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Jonesc7738402010-03-02 13:55:13 -0600486 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500487 * Set the controller overrides
Derek Jonesc7738402010-03-02 13:55:13 -0600488 *
489 * @access public
490 * @param array
491 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200492 */
Derek Jonesc7738402010-03-02 13:55:13 -0600493 function _set_overrides($routing)
494 {
495 if ( ! is_array($routing))
496 {
497 return;
498 }
Barry Mienydd671972010-10-04 16:33:58 +0200499
Derek Jonesc7738402010-03-02 13:55:13 -0600500 if (isset($routing['directory']))
501 {
502 $this->set_directory($routing['directory']);
503 }
Barry Mienydd671972010-10-04 16:33:58 +0200504
Derek Jonesc7738402010-03-02 13:55:13 -0600505 if (isset($routing['controller']) AND $routing['controller'] != '')
506 {
507 $this->set_class($routing['controller']);
508 }
Barry Mienydd671972010-10-04 16:33:58 +0200509
Derek Jonesc7738402010-03-02 13:55:13 -0600510 if (isset($routing['function']))
511 {
512 $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
513 $this->set_method($routing['function']);
514 }
515 }
516
517
Derek Allard2067d1a2008-11-13 22:59:24 +0000518}
519// END Router Class
520
521/* End of file Router.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600522/* Location: ./system/core/Router.php */