2011-04-12.txt. The following posts route will retrieve all of the file names found in a directory named entries, sorting the file names in reverse chronological order, and create user-friendly versions of those dates:dispatch('/posts', 'posts');
function posts()
{
// Retrieve all of the entries from the entries directory
foreach (glob("entries/*.txt") as $filename) {
$filenames[] = basename($filename, '.txt');
}
// Sort the files backwards according to date
krsort($filenames);
// Iterate over each file name and
// create a user-friendly version of the date
foreach ($filenames AS $filename)
{
$date = new DateTime($filename);
$dates[] = array('name' => $filename,
'date' => $date->format('F j, Y'));
}
// Set the $dates variable to the view scope
set('dates', $dates);
return html('posts.html.php', 'layout.html.php');
}/posts route produces output similar to that shown in Figure 2.
Figure 2. Displaying Blog Entries with Limonade Framework
http://dev.example.com/view/2011-04-13
view route, passing the date into the route so we can retrieve the entry:dispatch('/view/:date', 'view');
function view()
{
$date = params('date');
$entry = file_get_contents("entries/".$date.".txt");
set('entry', nl2br($entry));
return html('entry.html.php', 'layout.html.php');
}