diff --git a/Core/Router.php b/Core/Router.php index 63740bc..1c9ffc4 100644 --- a/Core/Router.php +++ b/Core/Router.php @@ -76,7 +76,13 @@ class Router public function match($url) { foreach ($this->routes as $route => $params) { + echo "
";
+            print_r($route);
+            echo "
"; if (preg_match($route, $url, $matches)) { + echo "
";
+                print_r($matches);
+                echo "
"; // Get named capture group values foreach ($matches as $key => $match) { if (is_string($key)) { @@ -110,23 +116,18 @@ class Router */ public function dispatch($url) { - $url = $this->removeQueryStringVariables($url); $url = str_replace($this->prefix,"",$url); - if ($this->match($url)) { $controller = $this->params['controller']; $controller = $this->convertToStudlyCaps($controller); $controller = $this->getNamespace() . $controller; if (class_exists($controller)) { $controller_object = new $controller($this->params); - $action = $this->params['action']; $action = $this->convertToCamelCase($action); - if (preg_match('/action$/i', $action) == 0) { - $controller_object->$action(); } else { throw new \Exception("Method $action in controller $controller cannot be called directly - remove the Action suffix to call this method"); diff --git a/public/index.php b/public/index.php index e36f706..8d3eca0 100644 --- a/public/index.php +++ b/public/index.php @@ -22,6 +22,8 @@ $router = new Core\Router(); // Add the routes $router->add('', ['controller' => 'Home', 'action' => 'index']); $router->add('{controller}/{action}'); +$router->add('{controller}/{action}/{paramater}'); + $router->AddPrefix(\App\Config::ROUTE_PREFIX); try{ //for prefight request