mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37: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) {
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user