From b858af3b55482e6d97a99e7e26554ba165019e60 Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Mon, 16 Sep 2024 06:47:00 -0700 Subject: [PATCH] updated routes for get and post --- examples/App/routes.php | 4 ++-- src/Router.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/App/routes.php b/examples/App/routes.php index 20dea35..ca0724a 100644 --- a/examples/App/routes.php +++ b/examples/App/routes.php @@ -1,9 +1,9 @@ [ - 'file' => 'about' + 'get' => 'about' ], '/' => [ - 'file' => 'index' + 'get' => 'index' ] ]; \ No newline at end of file diff --git a/src/Router.php b/src/Router.php index 1dc2a0f..79101d3 100644 --- a/src/Router.php +++ b/src/Router.php @@ -12,6 +12,7 @@ class Router { $this->routes = $this->loadRoutes(); $this->path = $this->preparePath(); $this->query = $this->prepareQuery(); + $this->request = $this->getRequestType(); $this->controller = $this->findController(); $this->controllerPath = $this->setRouteFile(); } @@ -47,11 +48,20 @@ class Router { return $queryArray; } + private function getRequestType() { + // is the requewst a get or post? + if (empty($_POST)) { + return 'get'; + } else { + return 'post'; + } + } + private function findController() { // one to one match if (array_key_exists($this->path, $this->routes)) { - return $this->routes[$this->path]['file']; + return $this->routes[$this->path][$this->request]; } foreach ($this->routes as $key => $value) {