PHP
  Home arrow PHP arrow Page 4 - Building an Extensible Menu Class
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building an Extensible Menu Class
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2001-08-10

    Table of Contents:
  • Building an Extensible Menu Class
  • Back To Class
  • What's On The Menu?
  • Children And Their Parents
  • I Say Method, You Say Madness...
  • Rounding Up The Family
  • Saving My Bookmarks
  • Reaching Higher
  • Collapsing Inwards
  • Extending Yourself

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building an Extensible Menu Class - Children And Their Parents


    (Page 4 of 10 )

    Now, the Menu object that I plan to build actually consists of two components: a database, and a series of functions to interact with it. The database contains all the raw data needed to generate the menu tree, while the class contains all the functions needed to massage the data into a useful format.

    I plan to use a very simple mySQL table to store all my menu information, as well as the relationships between the various levels of the tree - take a look:

    # # Table structure for table 'menu' # DROP TABLE IF EXISTS menu; CREATE TABLE menu ( id tinyint(3) unsigned NOT NULL auto_increment, label varchar(255) NOT NULL, link varchar(255), parent tinyint(3) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (id) ); # # id - unique identifier for each node # label - descriptive text for each node # link - URL for each node # parent - id of this node's parent #
    This design makes it easy to represent a hierarchical menu tree in terms of database records. For example, I could represent the following visual tree

    USA | | -- California | | -- Los Angeles | | -- Massachusetts | | -- Boston

    United Kingdom | | -- London

    as a series of records in the "menu" table. 
    

    mysql> SELECT * FROM menu; +----+------+----------------+--------+ | id | link | label | parent | +----+------+----------------+--------+ | 1 | | USA | 0 | | 2 | | California | 1 | | 3 | | Los Angeles | 2 | | 4 | | Massachusetts | 1 | | 5 | | Boston | 4 | | 6 | | United Kingdom | 0 | | 7 | | London | 6 | +----+------+----------------+--------+ 7 rows in set (0.00 sec)

    More PHP Articles
    More By Team Melonfire, (c) Melonfire


     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT