Skip to content

Instantly share code, notes, and snippets.

@drmcarvalho
Last active April 21, 2020 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmcarvalho/c954f4437a8be0d15b042b30ab701770 to your computer and use it in GitHub Desktop.
Save drmcarvalho/c954f4437a8be0d15b042b30ab701770 to your computer and use it in GitHub Desktop.
<?php
$routes = array(
'/hello' => 'hello.php',
'/user' => 'listar_usuario.php',
'/user/add' => 'adicionar_usuario.php'
);
function router($routes) {
// Iterate atraves da lista de rotas e faz include
foreach ($routes as $path => $include)
if ($path == $_SERVER['PATH_INFO']) {
return require $include;
}
echo 'Desculpe, pagina nao encontrada.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment