PHP Classes

PHP Tree Menu Maker: Display a hierarchic menu from an array of entries

Recommend this page to a friend!
  Info   View files Example   View files View files (27)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-06-15 (Yesterday) RSS 2.0 feedStarStarStarStar 63%Total: 1,047 This week: 3All time: 3,534 This week: 25Up
Version License PHP version Categories
tree-menu-maker 13GNU General Publi...5.0HTML, PHP 5
Description 

Author

This class can display a hierarchic menu from an array of entries.

It can take an array of entries that define a hierarchy by specifying the parent of each entry.

The class can generate HTML lists to display nested tree entries using data attrubutes to specify which ones should appear opened or closed by using a jQuery plugin.

Picture of Ali Sharifi
  Performance   Level  
Name: Ali Sharifi <contact>
Classes: 3 packages by
Country: Iran Iran
Innovation award
Innovation award
Nominee: 1x

Example

<?php
/**
 * Description of example for TreeMenu class
 *
 * @author ali sharifi
 * alisharifi01@gmail.com
 */
/*
 * tree menu class make a nested unordered list (ul li) from an array that store hierarchical data
 * if you dont know what is hierarchical data , check this http://www.sitepoint.com/hierarchical-data-database-2/
 */
include 'TreeMenu.class.php';
/*if you store your hierarchical data in a table of database ,
 *you should fetch the data in an array like $testArray and use treeMenu class !
 */
$testArray=array(
             array(
                       
"id" => 1,
                       
"name"=>"food" ,
                       
"parent" => NULL),
               array(
                        
"id" => 2,
                       
"name"=>"fruit" ,
                       
"parent" => NULL),
               array(
                       
"id" => 3,
                        
"name"=>"red" ,
                       
"parent" => 2),
              array(
                       
"id"=>4,
                       
"name"=>"yellow" ,
                       
"parent" => 2),
               array(
                        
"id"=>5,
                       
"name"=>"apple" ,
                       
"parent" => 3),
              array(
                        
"id"=>6,
                       
"name"=>"cherry" ,
                       
"parent" => 2),
               array(
                        
"id"=>7,
                       
"name"=>"bannana" ,
                       
"parent" => 4),
               array(
                       
"id"=>8,
                       
"name"=>"beef" ,
                       
"parent" => 1),
               array(
                        
"id"=>9,
                       
"name"=>"pork" ,
                       
"parent" => 1),
               array(
                        
"id"=>10,
                       
"name"=>"beafsteak" ,
                       
"parent" => 8),
                array(
                        
"id"=>11,
                       
"name"=>"pizza" ,
                       
"parent" => 8),
                array(
                        
"id"=>12,
                       
"name"=>"peperoni pizza" ,
                       
"parent" => 11),
                array(
                        
"id"=>13,
                       
"name"=>"vegetable pizza" ,
                       
"parent" => 11),
           );
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>example of TreeMenu class</title>
        <link href="themes/easyui.css" rel="stylesheet" type="text/css">
        <link href="themes/icon.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
</head>
<body>
    <?php
           
/*TreeMenu class get a 2 parameters , the first on is an array that store hierarchical data
            * and second one is the css class on master ul (the second parameter is optional).
            * In this example , I use Easy UI plugin to style the menu , you can use your style or your javascript code.
            * for more informatiomn about EASY UI plugin , check www.jeasyui.com
            */
           
new TreeMenu($testArray,"easyui-tree");
       
?>
</body>
</html>


Details

Tree Menu


  Files folder image Files  
File Role Description
Files folder imagejs (2 files)
Files folder imagethemes (2 files, 1 directory)
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file README.md Data Auxiliary data
Plain text file TreeMenu.class.php Class Class source

  Files folder image Files  /  js  
File Role Description
  Accessible without login Plain text file jquery.easyui.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.min.js Data Auxiliary data

  Files folder image Files  /  themes  
File Role Description
Files folder imageimages (20 files)
  Accessible without login Plain text file easyui.css Data Auxiliary data
  Accessible without login Plain text file icon.css Data Auxiliary data

  Files folder image Files  /  themes  /  images  
File Role Description
  Accessible without login Image file accordion_arrows.png Icon Icon image
  Accessible without login Image file blank.gif Icon Icon image
  Accessible without login Image file calendar_arrows.png Icon Icon image
  Accessible without login Image file combo_arrow.png Icon Icon image
  Accessible without login Image file datagrid_icons.png Icon Icon image
  Accessible without login Image file datebox_arrow.png Icon Icon image
  Accessible without login Image file layout_arrows.png Icon Icon image
  Accessible without login Image file linkbutton_bg.png Icon Icon image
  Accessible without login Image file loading.gif Icon Icon image
  Accessible without login Image file menu_arrows.png Icon Icon image
  Accessible without login Image file messager_icons.png Icon Icon image
  Accessible without login Image file pagination_icons.png Icon Icon image
  Accessible without login Image file panel_tools.png Icon Icon image
  Accessible without login Image file searchbox_button.png Icon Icon image
  Accessible without login Image file slider_handle.png Icon Icon image
  Accessible without login Image file spinner_arrows.png Icon Icon image
  Accessible without login Image file tabs_icons.png Icon Icon image
  Accessible without login Plain text file Thumbs.db Data Auxiliary data
  Accessible without login Image file tree_icons.png Icon Icon image
  Accessible without login Image file validatebox_warning.png Icon Icon image

 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,047
This week:3
All time:3,534
This week:25Up
User Ratings User Comments (2)
 All time
Utility:90%StarStarStarStarStar
Consistency:90%StarStarStarStarStar
Documentation:-
Examples:90%StarStarStarStarStar
Tests:-
Videos:-
Overall:63%StarStarStarStar
Rank:864
 
very good tool ;)
9 years ago (pooya sabramooz)
70%StarStarStarStar
Thats a good and useful class ;-)
9 years ago (José Filipe Lopes Santos)
70%StarStarStarStar