updated routes for get and post
This commit is contained in:
parent
937e4581ba
commit
b858af3b55
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
$routes = [
|
||||
'/about' => [
|
||||
'file' => 'about'
|
||||
'get' => 'about'
|
||||
],
|
||||
'/' => [
|
||||
'file' => 'index'
|
||||
'get' => 'index'
|
||||
]
|
||||
];
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user