Location: PHPKode > scripts > Accessible nested DHTML menus > accessible-nested-dhtml-menus/example1.php
<?php
/*
An example of how to use the menu statically.  

Author: Mick Sear
eCreate, July 2005
License: LGPL - This means you can use it in your apps (commercial as well as 
non-commercial, but this message must be kept intact, source code must be provided to 
clients, and changes to the code must be marked as by yourselves.
*/

  include("MenuNode.php");
  include("mcs_templater_class.php");

  //Build the menu
  //Start with a blank menu which is the overall container
  $a = &new MenuNode();
  
  //Create first level menu items
  $b = &new MenuNode();
  $c = &new MenuNode();
  $d = &new MenuNode();
  
  //Add them to the container as nodes
  $a->addNode($b, 'Level 1, Item 1', '#');
  $a->addNode($c, 'Level 1, Item 2', '#');
  $a->addNode($d, 'Level 1, Item 3', '#');
  
  
  //Add a couple of sub-nodes to Item2:
  //Create a new menu node instance
  $e = &new MenuNode();
  //Add it to level 2, which was variable $c, above.
  $c->addNode($e, 'Level 2, Item 1', '#');
  
  $f = &new MenuNode();
  $c->addNode($f, 'Level 2, Item 2', '#');
  
  //Add a third level, to $e:
  $g = &new MenuNode();
  $e->addNode($g, 'Level 3, Item 1', '#');  
  
  //A few other nodes, added with shorthand method.
  $d->addNode(($h = &new MenuNode()), 'Level 2, Item 1', '#');
  $d->addNode(($i = &new MenuNode()), 'Level 2, Item 2', '#');
  $d->addNode(($j = &new MenuNode()), 'Level 2, Item 3', '#');  

  $i->addNode(($k = &new MenuNode()), 'Level 3, Item 1', $_SERVER['PHP_SELF']);
  $i->addNode(($l = &new MenuNode()), 'Level 3, Item 2', '#');
  
  $j->addNode(($m = &new MenuNode()), 'Level 3, Item 1', '#');   
  $j->addNode(($n = &new MenuNode()), 'Level 3, Item 2', '#'); 
  
  $n->addNode(($o = &new MenuNode()), 'Level 4, Item 1', $_SERVER['PHP_SELF']);  

  //If you look at the template, you'll see placeholders (look like comments) called menu and javascript.
  $out['menu'] = $a->display();    
  $out['javascript'] = $a->getJavascript();
  
  //Give the associative array $out to the templater and display
  $template = new ms_template("template.htm", $out, "<!--::", "::-->");
  $template->parse_template();
  $template->display();
?>
Return current item: Accessible nested DHTML menus