1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-04 15:37:45 +02:00

Stripping basePath from route url, only adding it when appropriate. Fixes #38 and #20.

Fixes #38 and #20.
This commit is contained in:
Danny van Kooten
2013-11-08 15:58:39 +01:00
parent 77e77de9fa
commit 01258d15ef

View File

@@ -25,10 +25,6 @@ class AltoRouter {
*/
public function map($method, $route, $target, $name = null) {
if($route != '*') {
$route = $this->basePath . $route;
}
$this->routes[] = array($method, $route, $target, $name);
if($name) {
@@ -61,7 +57,9 @@ class AltoRouter {
// Replace named parameters
$route = $this->namedRoutes[$routeName];
$url = $route;
// prepend base path to route url again
$url = $this->basePath . $route;
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
@@ -101,6 +99,9 @@ class AltoRouter {
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
}
// strip base path from request url
$requestUrl = substr($requestUrl, strlen($this->basePath));
// Strip query string (?a=b) from Request Url
if (($strpos = strpos($requestUrl, '?')) !== false) {
$requestUrl = substr($requestUrl, 0, $strpos);