corrigindo rotas

This commit is contained in:
Reginaldo
2023-06-13 18:08:42 -03:00
parent 20fc580fe2
commit 00d21cc8c5
11 changed files with 182 additions and 22 deletions

30
routes/router.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
function load(string $controller, string $action){
try{
$controllerNameSpace = "app\\controllers\\{$controller}";
if(!class_exists($controllerNameSpace)){
throw new Exception("Controller {$controller} não existe");
}
$controllerInstance = new $controllerNameSpace();
if(!method_exists($controllerInstance,$action)){
throw new Exception("O método {$action} não existe");
}
$controllerInstance->$action();
}catch(Exception $e){
echo $e->getMessage();
}
}
$router= [
"GET"=>[
"/projeto/api_educa/"=> fn()=> load("HomeController","index"),
"/projeto/api_educa/login" => fn()=> load("LoginController","index")
],
"POST"=>[
"/projeto/api_educa/login" => fn()=> load("LoginController","store")
]
];