Create Front Controller

With one file handling all requests, you can centralize things such as security handling, configuration loading, and routing.
<?php
// index.php
// load and initialize any global libraries

require_once 'model.php';
require_once 'controllers.php';
// route the request internally

$uri = $_SERVER['REQUEST_URI'];
if ('/index.php' == $uri) 
{
list_action();
} elseif ('/index.php/show' == $uri && isset($_GET['id'])) {
show_action($_GET['id']);
} else {
header('Status: 404 Not Found');
echo '
<html><body><h1>Page Not Found</h1></body></html>';
}		
For organization, both controllers (formerly index.php and show.php) are now PHP functions and each has been moved into a separate file, controllers.php :
function list_action()
{
$posts = get_all_posts();
require 'templates/list.php';
}
function show_action($id)
{
$post = get_post_by_id($id);
require 'templates/show.php';
}