Home arrow PHP arrow Page 6 - Building A Quick-And-Dirty Guestbook With patGuestbook (part 1)

Code Poet - PHP

Want to plug into what your site visitors actually think? All you need is a little time, a dollop of imagination and a copy of patGuestbook. More, inside.

TABLE OF CONTENTS:
  1. Building A Quick-And-Dirty Guestbook With patGuestbook (part 1)
  2. Introductions
  3. Home Sweet Home
  4. The Voice Of The People
  5. Playing The Field
  6. Code Poet
  7. User, User, On The Wall...
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 49
February 28, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Now that the guestbook has been configured, all that's left is to integrate it into your Web site. And even that's a pretty simple task to accomplish - pop open the included sample PHP script, "example.php", which lives in your source distribution's root directory, and take a quick peek at what's inside it (I've added comments to the code so that it's easier to see what's happening):


<?php // include required classes require_once( "config/patGuestbook.php" ); require_once( "include/patGuestbook.php" ); require_once( "include/patTemplate.php" ); require_once( "include/patDbc.php" ); // initialize template engine $template = new patTemplate; // set base directory to look for templates $template->setBasedir( $skins_dir ); // initialize DB abstraction layer $dbc = new patMySqlDbc( $db_host, $db_name, $db_user, $db_pass ); // initialize guestbook $guestbook = new patGuestbook; // connect guestbook to template engine and DB connection $guestbook->setTemplate( $template ); $guestbook->setDbc( $dbc ); // set skin to use for guestbook if( !empty( $skin ) ) $guestbook->setSkin( $skin ); // display guestbook $guestbook->process( array( "name" => "Voice Of The People" ) ); ?>
Nothing too complicated here. First, the script include()-s the files that contain the API functions required by patGuestbook.

// include required classes require_once( "config/patGuestbook.php" ); require_once( "include/patGuestbook.php" ); require_once( "include/patTemplate.php" ); require_once( "include/patDbc.php" );
This is followed by initialization and creation of the patGuestbook object, which serves as the focal point for all future guestbook operations, together with the template engine and database connection point.

// initialize template engine $template = new patTemplate; // initialize DB abstraction layer $dbc = new patMySqlDbc( $db_host, $db_name, $db_user, $db_pass ); // initialize guestbook $guestbook = new patGuestbook; // connect guestbook to template engine and DB connection $guestbook->setTemplate( $template ); $guestbook->setDbc( $dbc );
Once that's done, the patGuestbook object's process() method can be used to select and display the guestbook.

// display guestbook $guestbook->process( array( "name" => "Voice Of The People" ) );
You can use the bare-bones skeleton above to create your own PHP scripts, or even integrate the lines of code above into your existing site. Either way, this is all you need to do to get a guestbook up and running. Painless, isn't it?

 
 
>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: