Why reinvent the wheel?
[*] First configuration file.
- Resources for the thread.
[list:74611b87b2]- Harry Fuecks (may 2005 edition): "The PHP Anthology: Object Oriented PHP Solutions Volume I and II".
- The code library that follows with the book, SPLIB.
- The low hanging fruit of OO PHP
config.php
<?php
ini_set('include_path',ini_get('include_path') . '../SPLIB:' . '../pear:');
?>
location: ../config
[*] Connection to the MySQL database.
connection.php
<?php
require_once('../config/config.php'); // Configuration file
// Include MySQL class
require_once('Database/MySQL.php'); // In SPLIB
$host='db.name.com'; // Hostname of MySQL server
$dbUser='Your user name'; // Username for MySQL
$dbPass='your password'; // Password for user
$dbName='Name of SQL DB'; // Database name
// Instantiate MySQL connection
$db=& new MySQL($host,$dbUser,$dbPass,$dbName);
?>
location: ../connection Only for testing. Hide it in your applications.
[*] SQL text files imported to MySQL via phpMyAdmin.
menu.sql
# phpMyAdmin MySQL-Dump
# version 2.3.0-rc3
# http://phpwizard.net/phpMyAdmin/
# http://www.phpmyadmin.net/ (download page)
#
# Host: localhost
# Generation Time: Sep 21, 2003 at 11:43 AM
# Server version: 4.00.00
# PHP Version: 4.3.2
# Database : `sitepoint`
# --------------------------------------------------------
#
# Table structure for table `menu`
#
CREATE TABLE menu (
menu_id int(11) NOT NULL auto_increment,
parent_id int(11) NOT NULL default '0',
name varchar(255) NOT NULL default '',
description text NOT NULL,
location varchar(255) NOT NULL default '',
PRIMARY KEY (menu_id),
UNIQUE KEY location (location)
) TYPE=MyISAM;
#
# Dumping data for table `menu`
#
INSERT INTO menu VALUES (1, 0, 'Home', 'Home', '/');
INSERT INTO menu VALUES (2, 1, 'News', 'Site news', '/news/');
INSERT INTO menu VALUES (3, 1, 'About', 'About us', '/about/');
INSERT INTO menu VALUES (4, 1, 'Contact', 'Contact Us', '/contact/');
INSERT INTO menu VALUES (5, 0, 'Products', 'Product Catalog', '/products/');
INSERT INTO menu VALUES (6, 5, 'Pets', 'The Petstore', '/products/pets/');
INSERT INTO menu VALUES (7, 6, 'Birds', 'The Aviary', '/products/pets/birds/');
INSERT INTO menu VALUES (8, 6, 'Cats', 'The Lions Den', '/products/pets/cats/');
INSERT INTO menu VALUES (9, 5, 'Books', 'The Bookstore', '/products/books/');
INSERT INTO menu VALUES (10, 9, 'Fiction', 'Fiction', '/products/books/fiction/');
INSERT INTO menu VALUES (11, 9, 'Biography', 'Biographies', '/products/books/biography/');
INSERT INTO menu VALUES (12, 3, 'Folio', 'Sites', '/about/folio/');
[*] Building a simple menu loaded from the Database.
File 12.php chapter 9 Vol I Fuecks modified.
<?php
require_once('../config/config.php'); // Modified
require_once('../connection/connection.php');
// Include MySQL class
require_once('Database/MySQL.php'); // SPLIB
// Include Menu class
require_once('UI/Menu.php'); // SPLIB
// Include BreadCrumb class
require_once('UI/BreadCrumb.php'); // SPLIB
// Set the base location for this page relative to web root - MODIFY THIS!!!
// Something curious here.
// http://www.kjellbleivik.com/WebPageElements/12.php/ OK
// http://www.kjellbleivik.com/WebPageElements/12.php Not OK
$baseUrl='/WebPageElements/12.php'; // Important modification from Fuecks code.
// Fetch the location frameelement to match against menu table
$location = str_replace ($baseUrl,'',$_SERVER['PHP_SELF']);
// Instantiate new BreadCrumb menu passing the MySQL connection and location
$crumbs=& new BreadCrumb($db,$location);
?>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> BreadCrumb Menu Example </title>
<meta http-equiv="Content-type" content="text/html"
charset="iso-8859-1" />
<style type="text/css">
body, a, li
{
font-family: verdana;
font-size: 11px;
}
h1
{
font-family: verdana;
font-size: 15px;
color: navy
}
.breadCrumbs
{
margin-bottom: 10px;
border-style: dashed;
border-width: 2px;
padding: 4px;
width: 400px;
}
</style>
</head>
<body>
<h1>Bread Crumbs Menu</h1>
<div class="breadCrumbs">
<?php
// Display the breadcrumbs
while ( $item = $crumbs->fetch() ) {
if ( $item->isRoot() ) {
echo ( "<a href=\"".$baseUrl.$item->location()."\">"
.$item->name()."</a>" );
} else {
echo ( " > <a href=\"".$baseUrl.$item->location()."\">"
.$item->name()."</a>" );
}
}
?>
</div>
Sample Urls:
Contact
Folio
Products
Fiction
</body>
</html>
[*] Online Result
[*] Have I forgotten something e.g. a .sql file? I have not checked that well enough.
[/list:o:74611b87b2]
Submit Your Article
Forum Rules

Reply With Quote
