lib directory into your Web project's home directory. Next, create a file named index.php and add the following contents to it:<?php
require_once 'lib/limonade.php';
// Application code goes here
run();
.htaccess file which will route all requests to a file named index.php:<IfModule mod_rewrite.c>
Options +FollowSymlinks
Options +Indexes
RewriteEngine on
# RewriteBase /path/ # If website in subdirectory, uncomment and change this
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [NC,L]
</IfModule>dispatch() method, which you'll use to identify each end point and its associated method. For instance, the following dispatch() call ties a method named welcome() to the website's home page:dispatch('/', 'welcome');welcome() method and within it, use Limonade's html() method to identify a view (page template) associated with the page:function welcome()
{
return html('index.html.php');
}views within your project home directory, so create that directory and within it, create a file named index.html.php, adding the following contents:<html>
<head>
<title>Welcome to My Exercise Diary</title>
</head>
<body>
<p>
Return often to receive updates about the trials and tribulations
surrounding raising my heart rate beyond 80bpm!
</p>
</body>
</html>
Click here for larger image
Figure 1. A Limonade-powered Homepage
dispatch() call and associated method for each. For instance, a route definition pointing to /about would look like this:dispatch('/about', 'about');
function about()
{
return html('about.html.php');
}title tags) would be quite a chore. Fortunately, you can eliminate the redundancy by using Limonade's layout feature. Let's explore this feature by modifying your welcome() method call to look like this:function welcome()
{
return html('index.html.php', 'layout.html.php');
}layout.html.php file contains the global template which the associated view is injected into with each request. The injection occurs where the global template outputs the $content variable, as demonstrated here:<html>
<head>
<title>Welcome to My Exercise Diary</title>
</head>
<body>
<?php echo $content; ?>
</body>
</html>index.html.php view, leaving only the introductory paragraph:<p>
Return often to receive updates about the trials and tribulations
surrounding raising my heart rate beyond 80bpm!
</p>
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');
}