iLexN
8/18/2015 - 3:41 AM

route

route

<?php 
$routes = [
  '/'       => function() { return '<a href="/hello">Click here for a greeting</a>'; },
  '/hello'  => function() { return 'Hello world'; },
  '404'     => function() { return 'Page not found'; }
];


$request = $_SERVER['REQUEST_URI'];
$response = false;
// Find a route and define the response
foreach($routes as $route=>$action) {
	if($request == $route) {
		$response = $action;
	}
}
// If no route was found, use the 404 route as the response
if($response === false) {
	$response = $routes['404'];
}
// Output the response
echo $response();