WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP 5 Object Based Menu's
Categories : PHP, PHP Classes Click here to Update Your Picture
Joseph Crawford
Date : Feb 09th 2005
Grade : 3 of 5 (graded 7 times)
Viewed : 5612
File : 4071.php
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
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
'&nbsp; &nbsp;<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