HomePHP Page 3 - Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
If Looks Could Kill... - PHP
In this concluding article of our two-part series on rapid guestbook implementation with patGuestbook, find out how to tweak patGuestbook a litle more by controlling the viewable entries, customizing the user interface, and protecting access to the administration module.
Next up, interface customization. As you may already know, patGuestbook is tightly integrated with a sister project, patTemplate, a powerful PHP-based template engine (if you don't know how patTemplate works, you should read the introductory material at Template-Based Web Development With patTemplate and only then proceed forward with this tutorial). This template engine makes it fairly easy to create your own skins for the patGuestbook interface (and even share them with others, if you so desire).
First things first - where are the templates located? If you recollect, this location was specified as part of the configuration parameters located in the "patGuestbook.php" file in your installation's "config" directory:
// Directory where the templates for subscription pages are
$skins_dir = "skins";
Look inside this directory, and you'll see a structure like this:
Do those directory names ring a bell? They should - they're the template names
that appear every time you create a new guestbook. So, if you want to create your own set of templates, this is obviously a good way to start.
Now, the patGuestbook application uses three different templates for rendering the user interface:
1. patGuestbookList.tmpl - this is the template that displays the entries in the guestbook
2. patGuestbookAdd.tmpl - this is the template which handles adding new entries to the guestbook
3. patGuestbookDisabled.tmpl - this template simply displays an error message when a particular guestbook is disabled
Let's start with the "patGuestbookList.tmpl" file. To make things easier, I'll give you a quick peek at the desired output before I explain the template's innards to you.
Now, if you take a close look at it, you'll see that this is very similar to the "textonly" template - all I've really done is add a navigation menu to the left side of the page.
I'm going to call my new template "melonfire" (feel free to name your appropriately), and so my first task is to create a directory parallel to the "pat' and "textonly" folders in the "skins" directory. Under this directory, I'll add an "img" directory to store images, and a "styles" directory to store stylesheets.
Next up, the page layout. After much thought and coffee-napkin scrawls, I decided on a simple two-column layout for my guestbook, with the navigation bar in the left column and the main guestbook content in the right one. Here's the basic skeleton:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN"> <html>
text="#000000" link="#990000" vlink="#990000"
rightmargin="10" bottommargin="10" leftmargin="10">
src="skins/melonfire/img/px.gif" width="1" height="10" alt=""
<div align="center"> <table border="0" cellpadding="0"
<td width="25%" align="center">
<!-- menu comes
<td width="75%" align="center">
guestbook pages come here -->
Since the menu on the left is going to be constant across all pages, it can be
hardcoded into the template - here it is: