Skip to content
This repository
Browse code

Allow custom prefixes for controllers

This allows you to move controllers into a different folder structure,
and allow you to namespace them
  • Loading branch information...
commit 882e564de66dc3f4edf83181b8fa36a8a8b083cd 1 parent f57c376
Harro Verton authored

Showing 1 changed file with 18 additions and 3 deletions. Show diff stats Hide diff stats

  1. 21  classes/router.php
21  classes/router.php
@@ -14,10 +14,25 @@
14 14
 
15 15
 class Router
16 16
 {
17  
-
  17
+	/**
  18
+	 *
  19
+	 */
18 20
 	public static $routes = array();
19 21
 
20 22
 	/**
  23
+	 * Defines the controller class prefix. This allows you to namespace controllers
  24
+	 */
  25
+	protected static $prefix = '';
  26
+
  27
+	/**
  28
+	 * Fetch the controller prefix to be used, or set a default if not defined
  29
+	 */
  30
+	public static function _init()
  31
+	{
  32
+		static::$prefix = \Config::get('controller_prefix', 'Controller_');
  33
+	}
  34
+
  35
+	/**
21 36
 	 * Add one or multiple routes
22 37
 	 *
23 38
 	 * @param  string
@@ -245,7 +260,7 @@ protected static function parse_segments($segments, $namespace = '', $module = f
245 260
 
246 261
 		foreach (array_reverse($segments, true) as $key => $segment)
247 262
 		{
248  
-			$class = $namespace.'Controller_'.\Inflector::words_to_upper(implode('_', $temp_segments));
  263
+			$class = $namespace.static::$prefix.\Inflector::words_to_upper(implode('_', $temp_segments));
249 264
 			array_pop($temp_segments);
250 265
 			if (class_exists($class))
251 266
 			{
@@ -260,7 +275,7 @@ protected static function parse_segments($segments, $namespace = '', $module = f
260 275
 		// Fall back for default module controllers
261 276
 		if ($module)
262 277
 		{
263  
-			$class = $namespace.'Controller_'.ucfirst($module);
  278
+			$class = $namespace.static::$prefix.ucfirst($module);
264 279
 			if (class_exists($class))
265 280
 			{
266 281
 				return array(

0 notes on commit 882e564

Please sign in to comment.
Something went wrong with that request. Please try again.