[BUGFIX] Bugfixing

- Urls now always returns ending slash when using getRoute().
- Fixed common errors with routing.
- Simplified getRoute method.
This commit is contained in:
Simon Sessingø
2015-10-20 23:54:05 +02:00
parent 37b8090dac
commit 2524428926
+12 -8
View File
@@ -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);
}