From a101c93b93b43ac98370bb0a1378a82ff44e4e1a Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Fri, 20 Jul 2012 12:23:43 +0200 Subject: allow for routes that can be processed with php, ex: $route['([^/]+)/([^/]+)(/:any)?'] = 'php:"$1" . "/do" . ucfirst("$2") . "$3"'; --- system/core/Router.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Router.php b/system/core/Router.php index 5bc053045..cb7df5320 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -86,6 +86,13 @@ class CI_Router { * @var string */ public $default_controller; + + /** + * Prepend used in php processed routes + * + * @var string + */ + public $route_prepend = 'php:'; /** * Constructor @@ -373,10 +380,16 @@ class CI_Router { // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri)) { + // Are we using php functions to process matches? + $modifier = strpos($val, $this->route_prepend) === 0? 'e': ''; + + // If we have the 'e' modifier, remove the prepend from the route value. + $val = $modifier === 'e'? substr($val, strlen($this->route_prepend)): $val; + // Do we have a back-reference? if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { - $val = preg_replace('#^'.$key.'$#', $val, $uri); + $val = preg_replace('#^'.$key.'$#'.$modifier, $val, $uri); } return $this->_set_request(explode('/', $val)); -- cgit v1.2.3-24-g4f1b