Like this code?
Show the author your appreciation.
This is some code i worked up tonight out of sheer boredom, this can be modified so that you could easilly populate the menu's from database content. You can also modify this so that only certain groups/links will be shown based on the users level. I will be modifying the code to do that myself.
menu.php
<?php
/******************************************
**
** The following code was written by
** Joseph Crawford Jr. (codebowl@gmail.com)
** This code is free to use, for non profit
** websites, please leave this comment in
** tact when using this code.
**
******************************************/
class Menu {
static private $_groups ;
public function __construct () {
$this -> _groups = array();
}
public function GetIndex ( $title ) {
foreach( self :: $_groups as $key => $group ) {
if( strtolower ( $group -> Title () ) == strtolower ( $title ) ) {
return $key ;
}
}
return - 1 ;
}
static public function Group ( $index = - 1 ) {
if( ( $index == - 1 ) && ( count ( self :: $_groups ) != 0 ) ) $index = count ( self :: $_groups );
else $index = 0 ;
if( self :: $_groups [ $index ] == null ) {
self :: $_groups [ $index ] = new MenuGroup ();
}
return self :: $_groups [ $index ];
}
public function Draw () {
foreach( self :: $_groups as $gkey => $group ) {
echo $group -> Title (). '<br>' ;
$items = $group -> GetItems ();
foreach( $items as $item ) {
echo ' <a href="' . $item -> Link (). '">' . $item -> Title (). '</a><br>' ;
}
}
}
}
class MenuGroup {
static private $_items ;
private $_order ;
private $_title ;
public function __construct ( ) {
self :: $_items = array();
}
public function Title ( $var = "" ) {
if( $var != "" ) {
$this -> _title = $var ;
}
return $this -> _title ;
}
public function GetIndex ( $title ) {
foreach( self :: $_items as $key => $item ) {
if( strtolower ( $item -> Title () ) == strtolower ( $title ) ) {
return $key ;
}
}
return - 1 ;
}
static public function Item ( $index = - 1 ) {
if( ( $index == - 1 ) && ( count ( self :: $_items ) != 0 ) ) $index = count ( self :: $_items );
else $index = 0 ;
if( self :: $_items [ $index ] == null ) {
self :: $_items [ $index ] = new MenuItem ();
}
return self :: $_items [ $index ];
}
public function GetItems () {
return self :: $_items ;
}
}
class MenuItem {
private $_order ;
private $_title ;
private $_link ;
public function __construct ( $order = 0 ) {
$this -> _order = $order ;
}
public function Title ( $var = "" ) {
if( $var != "" ) {
$this -> _title = $var ;
}
return $this -> _title ;
}
public function Link ( $var = "" ) {
if( $var != "" ) {
$this -> _link = $var ;
}
return $this -> _link ;
}
}
?>
an example of using this code
<?
include_once( "menu.php" );
$menu = new Menu ();
$general = $menu -> Group ();
$general -> Title ( "General" );
$home = $general -> Item ();
$home -> Title ( "Home" );
$home -> Link ( "home.php" );
$faq = $general -> Item ();
$faq -> Title ( "FAQ" );
$faq -> Link ( "faq.php" );
// where ever you want the menu you call this method.
$menu -> Draw ();
?>
comments wanted :D
Timer - a class that uses microtime() to provide easy calculation of elapsed times Categories : Algorithms , PHP , PHP Classes Recordset Class for MSSQL database Categories : PHP Classes , Databases , PHP , MS SQL Server Objects to XML Serializer/Unserializer Categories : PHP , PHP Classes , DOM XML , Serialize RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP , XML , PHP Classes , Rich Site Summary (RSS) Antispoof - a class to help prevent people hi-jacking and misusing parts of a website Categories : PHP , PHP Classes , Security cPanel Subdomains Creator - Create cPanel subdomains without logging into cPanel. Let your visitors create their own subdomains without your intervention. Moreover, it will inform if a subdomain is already exists. Categories : PHP , Web Services , PHP Classes Writing Portable MySQL Code in PHP: Porting to Oracle, Microsoft SQL
Server, Sybase, Interbase, PostgreSQL and other databases using ADODB
class library. Categories : MySQL , PHP , PHP Classes , ODBC , General SQL Forms protected from XSS attacks (FOPAXSS) Categories : PHP , PHP Classes , Form Processing , Security Access_user Class - an easy to use system for protecting pages and register users. Categories : PHP , Classes and Objects , Object Oriented , PHP Classes , Authentication Database and Recordset classes fo SyBASE Usage is obvious. Categories : Sybase , Databases , PHP Classes , PHP O-LOC : PHP 5.x Internationalization class and back-office. manage the display of translations on a localized web application. Categories : PHP , PHP Classes , Web Applications , Languages , DOM XML Url To Pdf Report By Remote Application Categories : PHP , PHP Classes , PDF , CURL PHP4 DirectoryIterator Class Categories : PHP , PHP Classes , Filesystem , Directories a class for doing payments to a cybercash server
Categories : Ecommerce , Complete Programs , PHP Classes , PHP MySQL Handler Categories : PHP , Databases , MySQL , Classes and Objects , PHP Classes