diff options
author | Roman Tsiupa <draconyster@gmail.com> | 2013-02-26 22:30:07 +0200 |
---|---|---|
committer | Roman Tsiupa <draconyster@gmail.com> | 2013-02-26 22:30:07 +0200 |
commit | 5401ac6ec6da5ad70c5ca73753447cca859699a2 (patch) | |
tree | 2dbbcf6f0f7644cda2adcfb26b1dbd9d13bd2910 /system/classes | |
parent | 1690da36a5c5ad309de7117f3d8b52f045ebc9bf (diff) | |
download | PHPixie-5401ac6ec6da5ad70c5ca73753447cca859699a2.zip PHPixie-5401ac6ec6da5ad70c5ca73753447cca859699a2.tar.gz PHPixie-5401ac6ec6da5ad70c5ca73753447cca859699a2.tar.bz2 |
Support for optional parameters
Diffstat (limited to 'system/classes')
-rw-r--r-- | system/classes/route.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/system/classes/route.php b/system/classes/route.php index c1b9457..244a0c7 100644 --- a/system/classes/route.php +++ b/system/classes/route.php @@ -80,13 +80,19 @@ class Route { $url = is_array($this->rule)?$this->rule[0]:$this->rule; - $replace = array('(' => '', ')' => ''); + $replace = array(); $params = array_merge($this->defaults, $params); foreach($params as $key => $value) $replace["<{$key}>"] = $value; - $url = str_replace(array_keys($replace), array_values($replace), $url); + $count = 1; + $chars='[^\(\)]*?'; + while($count>0) + $url = preg_replace("#\({$chars}<{$chars}>{$chars}\)#", '', $url, -1, $count); + + $url = str_replace(array('(', ')'), '', $url); + if ($absolute) $url = $protocol.'://'.$_SERVER['HTTP_HOST'].$url; |