mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
[BUGFIX] Bugfixing
- Urls now always returns ending slash when using getRoute(). - Fixed common errors with routing. - Simplified getRoute method.
This commit is contained in:
@@ -165,10 +165,10 @@ class RouterBase {
|
|||||||
|
|
||||||
protected function processUrl($route, $method = null, $parameters = null, $getParams = null) {
|
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) {
|
if(($route instanceof RouterController || $route instanceof RouterRessource) && $method !== null) {
|
||||||
$url .= $method . '/';
|
$url .= $method;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($route instanceof RouterController || $route instanceof RouterRessource) {
|
if($route instanceof RouterController || $route instanceof RouterRessource) {
|
||||||
@@ -182,18 +182,17 @@ class RouterBase {
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
foreach($params as $param => $value) {
|
foreach($params as $param => $value) {
|
||||||
$value = (isset($parameters[$param])) ? $parameters[$param] : $value;
|
$value = (isset($parameters[$param])) ? $parameters[$param] : $value;
|
||||||
$url = str_ireplace('{' . $param. '}', $value, $route->getUrl());
|
$url = str_ireplace('{' . $param. '}', $value, $url);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$p = '';
|
$url = rtrim($url, '/') . '/';
|
||||||
if($getParams !== null && count($getParams)) {
|
|
||||||
$p = '?'.Url::arrayToParams($getParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
$url .= $p;
|
if($getParams !== null && count($getParams)) {
|
||||||
|
$url .= '?'.Url::arrayToParams($getParams);
|
||||||
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
@@ -208,6 +207,10 @@ class RouterBase {
|
|||||||
throw new \InvalidArgumentException('Invalid type for getParams. Must be array or null');
|
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 = '';
|
$c = '';
|
||||||
$method = null;
|
$method = null;
|
||||||
|
|
||||||
@@ -252,6 +255,7 @@ class RouterBase {
|
|||||||
if(is_array($parameters)) {
|
if(is_array($parameters)) {
|
||||||
ArrayUtil::append($url, $parameters);
|
ArrayUtil::append($url, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
return join('/', $url);
|
return join('/', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user