From 25244289261b703cfea00212e56cb30d3bbfe1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Tue, 20 Oct 2015 23:54:05 +0200 Subject: [PATCH] [BUGFIX] Bugfixing - Urls now always returns ending slash when using getRoute(). - Fixed common errors with routing. - Simplified getRoute method. --- src/Pecee/SimpleRouter/RouterBase.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 4fd9d76..0817c9f 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -165,10 +165,10 @@ class RouterBase { protected function processUrl($route, $method = null, $parameters = null, $getParams = null) { - $url = rtrim($route->getUrl(), '/') . '/'; + $url = $route->getUrl(); if(($route instanceof RouterController || $route instanceof RouterRessource) && $method !== null) { - $url .= $method . '/'; + $url .= $method; } if($route instanceof RouterController || $route instanceof RouterRessource) { @@ -182,18 +182,17 @@ class RouterBase { $i = 0; foreach($params as $param => $value) { $value = (isset($parameters[$param])) ? $parameters[$param] : $value; - $url = str_ireplace('{' . $param. '}', $value, $route->getUrl()); + $url = str_ireplace('{' . $param. '}', $value, $url); $i++; } } } - $p = ''; - if($getParams !== null && count($getParams)) { - $p = '?'.Url::arrayToParams($getParams); - } + $url = rtrim($url, '/') . '/'; - $url .= $p; + if($getParams !== null && count($getParams)) { + $url .= '?'.Url::arrayToParams($getParams); + } return $url; } @@ -208,6 +207,10 @@ class RouterBase { throw new \InvalidArgumentException('Invalid type for getParams. Must be array or null'); } + if($controller === null && $parameters === null) { + return $this->processUrl($this->loadedRoute, null, $getParams); + } + $c = ''; $method = null; @@ -252,6 +255,7 @@ class RouterBase { if(is_array($parameters)) { ArrayUtil::append($url, $parameters); } + return join('/', $url); }