ApPHP TreeMenu Advanced v.2.1.2 - Example of code

   [View LIVE DEMO]     [Back to Site]

Show Plain Text »
  1. <?php
  2.  
  3.    ## +---------------------------------------------------------------------------+
  4.    ## | 1. Creating & Calling:                                                    |
  5.    ## +---------------------------------------------------------------------------+
  6.    ## *** define a relative (virtual) path to treemenu.class.php file
  7.    define ("TREEMENU_DIR", "");                  /* Ex.: "treemenu/" */
  8.    ## *** include TreeMenu class
  9.    require_once(TREEMENU_DIR."treemenu.class.php");
  10.    ## *** create TreeMenu object
  11.    $treeMenu = new TreeMenu();
  12.  
  13.    ## +---------------------------------------------------------------------------+
  14.    ## | 2. General Settings:                                                      |
  15.    ## +---------------------------------------------------------------------------+
  16.    ## *** set unique identifier for TreeMenu
  17.    ## *** (if you want to use several independently configured TreeMenu objects on single page)
  18.    $treeMenu->SetId(1);
  19.    ##  *** set style for TreeMenu
  20.    ##  *** "default" or "xp" or "vista" or "paneled" or your own style
  21.    $treeMenu->SetStyle("paneled");
  22.    ## *** set TreeMenu caption
  23.    $treeMenu->SetCaption("ApPHP TreeMenu v".$treeMenu->Version());
  24.    ## *** show debug info - false|true
  25.    $treeMenu->Debug(false);
  26.    ## *** set postback method: "get", "post" or "ajax"
  27.    $treeMenu->SetPostBackMethod("ajax");
  28.    ## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
  29.    /// $treeMenu->SetHttpVars(array("id"));
  30.    ## *** show number of subnodes to the left of every node - false|true
  31.    /// $treeMenu->ShowNumSubNodes(false);
  32.    ## *** use an anchor to navigate to treemenu object after a node is clicked - true|false
  33.    /// $treeMenu->UseAnchor(false);
  34.    ## *** create the anchor automatically - true|false
  35.    /// $treeMenu->CreateAnchorAuto(false);
  36.    ## *** if the CreateAnchorAuto is set to true you have to create the anchor manually
  37.    /// <a name="treemenu"></a>
  38.    ## *** set TreeMenu direction: ltr - left-to-right or rtl - right-to-left
  39.    /// $treeMenu->SetDirection("ltr");
  40.  
  41.    ## +---------------------------------------------------------------------------+
  42.    ## | 3. Adding nodes:                                                          |
  43.    ## +---------------------------------------------------------------------------+
  44.    ## *** add nodes
  45.    ## arguments:
  46.    ## arg #1 - node's caption
  47.    ## arg #2 - file associated with this node (optional)
  48.    ## arg #3 - icon associated with this node (optional)
  49.    ## Example 1: $treeMenu->AddNode("Title");
  50.    ## Example 2: $treeMenu->AddNode("Title", "text.txt");
  51.    ## Example 3: $treeMenu->AddNode("Title", "text.txt", "icon.gif");
  52.    $root = $treeMenu->AddNode("Title");
  53.    $son = $root->AddNode("Son's Title");
  54.    $second = $root->AddNode("2nd son's Title", "index.html");
  55.  
  56.    ## *** associate a tab with HTML code snippet:
  57.    /// $son->SetInnerHTML("<b><i><span onclick='alert(\"How do you do?\")'>HTML</span></i> code snippet</b>");
  58.    ## *** open a node in a new window
  59.    /// $second->OpenNewWindow(true);
  60.    ## *** set a tooltip for a node
  61.    /// $son->SetTooltip("Son tab's tooltip");
  62.  
  63.    ## +---------------------------------------------------------------------------+
  64.    ## | 4. Building tree menu from contents of a folder:                                                          |
  65.    ## +---------------------------------------------------------------------------+
  66.    ## *** build a tree menu from contents of a folder
  67.    /// $treeMenu->BuildFromFolder("styles");
  68.    ## *** use default icons for folder nodes - false|true
  69.    /// $treeMenu->UseDefaultFolderIcons(false);
  70.    ## *** use default icons for file nodes - false|true
  71.    /// $treeMenu->UseDefaultFileIcons(false);
  72.  
  73.    ## +---------------------------------------------------------------------------+
  74.    ## | 5. Draw TreeMenu:                                                      |
  75.    ## +---------------------------------------------------------------------------+
  76.    $treeMenu->ShowTree();
  77.    $treeMenu->ShowContent();
  78.    
  79. ?>