PHP
  Home arrow PHP arrow Page 9 - 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 - Collapsing Inwards
    ( Page 9 of 10 )

    If you go back a few pages, you'll notice that one of the design goals of this Menu object was to separate the visual presentation of a menu from the relationships between the various nodes. I've already demonstrated how the same Menu object can be used to create a directory and a hierarchical menu tree with standard methods.

    My third example is similar to the second, again connecting a JavaScript-based menu system to the menu database to dynamically build a menu tree. For this, I plan to use another very popular menu constructor, FolderTree (free version available at http://www.geocities.com/marcelino_martins/foldertree.html ), which uses Windows Explorer-style files and folders to display a hierarchy of items.

    First, I need an HTML page to invoke FolderTree and display the menu:

    <html> <head> <basefont face="Arial"> <link rel="stylesheet" href="ftie4style.css"> <!-- Infrastructure code for the tree --> <script src="ftiens4.js"></script> <!-- Execution of the code that actually builds the specific tree --> <script src="menu.js.php"></script> <script> initializeDocument() </script> </head> <body bgcolor=white> </body> </html>
    As you can see, this file sources "menu.js.php", which contains the actual menu data. This file is usually created manually as per the user's requirements; I plan to hook it up to my database table to generate it dynamically. Here's the code:

    // menu.js.php // set up tree root foldersTree = gFld("Melonfire", "http://www.melonfire.com"); <? // initialize object include("menu.class.php"); $obj = new Menu(); // counter - used to create tree nodes $count = 0; function buildMenu($id, $node) { global $obj; global $count; // get children $children = $obj->get_children($id); for ($x=0; $x<sizeof($children); $x++) { // write the name of this node $newNode = "aux" . $count; // if folder if($obj->get_type($children[$x]["id"]) == 1) { // call appropriate FolderTree function to display folder icon $count++; $str = $newNode . " = insFld(" . $node . ", gFld(\"" . $children[$x]['label'] . "\", \"" . $children[$x]['link'] . "\"));"; print $str; // and recurse for next level buildMenu($children[$x]["id"], $newNode); } else { // if last level // call appropriate FolderTree function to display file icon $str = "insDoc(" . $node . ", gLnk(2, \"" . $children[$x]['label'] . "\", \"" . $children[$x]['link'] . "\"));"; print $str; } } } // initiate recursive function buildMenu(0, "foldersTree"); ?>
    You just gotta love those recursive functions!

    Here's what it all looks like:



     
     
    >>> 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 6 Hosted by Hostway
    Stay green...Green IT