Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@WanWizard WanWizard authored
Showing with 18 additions and 3 deletions.
  1. +18 −3 classes/router.php
View
21 classes/router.php
@@ -14,10 +14,25 @@
class Router
{
-
+ /**
+ *
+ */
public static $routes = array();
/**
+ * Defines the controller class prefix. This allows you to namespace controllers
+ */
+ protected static $prefix = '';
+
+ /**
+ * Fetch the controller prefix to be used, or set a default if not defined
+ */
+ public static function _init()
+ {
+ static::$prefix = \Config::get('controller_prefix', 'Controller_');
+ }
+
+ /**
* Add one or multiple routes
*
* @param string
@@ -245,7 +260,7 @@ protected static function parse_segments($segments, $namespace = '', $module = f
foreach (array_reverse($segments, true) as $key => $segment)
{
- $class = $namespace.'Controller_'.\Inflector::words_to_upper(implode('_', $temp_segments));
+ $class = $namespace.static::$prefix.\Inflector::words_to_upper(implode('_', $temp_segments));
array_pop($temp_segments);
if (class_exists($class))
{
@@ -260,7 +275,7 @@ protected static function parse_segments($segments, $namespace = '', $module = f
// Fall back for default module controllers
if ($module)
{
- $class = $namespace.'Controller_'.ucfirst($module);
+ $class = $namespace.static::$prefix.ucfirst($module);
if (class_exists($class))
{
return array(

0 comments on commit 882e564

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