corrigindo rotas
This commit is contained in:
30
routes/router.php
Normal file
30
routes/router.php
Normal 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")
|
||||
]
|
||||
];
|
||||
Reference in New Issue
Block a user