From 2cc97c120f73491e0b8ce0ea006390a194693f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Mon, 21 Nov 2016 07:56:37 +0100 Subject: [PATCH] Enhancements - Added example on how to get current url in documentation. - Fixed so urls always ends with /. --- README.md | 5 +++++ src/Pecee/SimpleRouter/Router.php | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22ad391..8a1bd96 100644 --- a/README.md +++ b/README.md @@ -402,6 +402,11 @@ url('phones.edit'); # /phones/edit/ ``` +**Return the current url** +```php +url(); +``` + ## Custom CSRF verifier Create a new class and extend the ```BaseCsrfVerifier``` middleware class provided with simple-php-router. diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php index c40ac9c..a5786e0 100644 --- a/src/Pecee/SimpleRouter/Router.php +++ b/src/Pecee/SimpleRouter/Router.php @@ -396,7 +396,8 @@ class Router /* Return current route if no options has been specified */ if ($name === null && $parameters === null) { - return '/' . trim(parse_url($this->request->getUri(), PHP_URL_PATH), '/') . $this->arrayToParams($getParams); + $url = rtrim(parse_url($this->request->getUri(), PHP_URL_PATH), '/'); + return (($url === '') ? '/' : $url . '/') . $this->arrayToParams($getParams); } /* If nothing is defined and a route is loaded we use that */