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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT