updated routes for get and post

This commit is contained in:
Nick Yeoman 2024-09-16 06:47:00 -07:00
parent 937e4581ba
commit b858af3b55
2 changed files with 13 additions and 3 deletions

View File

@ -1,9 +1,9 @@
<?php
$routes = [
'/about' => [
'file' => 'about'
'get' => 'about'
],
'/' => [
'file' => 'index'
'get' => 'index'
]
];

View File

@ -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) {