mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 22:12:18 +00:00
@@ -219,13 +219,16 @@ class RouterBase {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getParamsToArray($query) {
|
public function arrayToParams(array $getParams = null, $includeEmpty = true) {
|
||||||
$output = array();
|
if (is_array($getParams) && count($getParams) > 0) {
|
||||||
if($query[0] === '?') {
|
foreach ($getParams as $key => $val) {
|
||||||
$query = substr($query, 1);
|
if (!empty($val) || empty($val) && $includeEmpty) {
|
||||||
|
$getParams[$key] = $key . '=' . $val;
|
||||||
}
|
}
|
||||||
parse_str($query, $output);
|
}
|
||||||
return $output;
|
return join('&', $getParams);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processUrl($route, $method = null, $parameters = null, $getParams = null) {
|
protected function processUrl($route, $method = null, $parameters = null, $getParams = null) {
|
||||||
@@ -261,7 +264,7 @@ class RouterBase {
|
|||||||
$url = rtrim($url, '/') . '/';
|
$url = rtrim($url, '/') . '/';
|
||||||
|
|
||||||
if($getParams !== null && count($getParams)) {
|
if($getParams !== null && count($getParams)) {
|
||||||
$url .= '?' . $this->getParamsToArray($getParams);
|
$url .= '?' . $this->arrayToParams($getParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
@@ -342,8 +345,9 @@ class RouterBase {
|
|||||||
|
|
||||||
$url = '/' . trim(join('/', $url), '/') . '/';
|
$url = '/' . trim(join('/', $url), '/') . '/';
|
||||||
|
|
||||||
if(is_array($getParams)) {
|
|
||||||
$url .= '?' . $this->getParamsToArray($getParams);
|
if($getParams !== null && count($getParams)) {
|
||||||
|
$url .= '?' . $this->arrayToParams($getParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
|
|||||||
Reference in New Issue
Block a user