PHP Classes

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

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-06-15 (10 months ago) RSS 2.0 feedStarStarStarStar 63%Total: 1,050 This week: 1All time: 3,525 This week: 42Up
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  
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 (27)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,050
This week:1
All time:3,525
This week:42Up
User Ratings User Comments (2)
 All time
Utility:90%StarStarStarStarStar
Consistency:90%StarStarStarStarStar
Documentation:-
Examples:90%StarStarStarStarStar
Tests:-
Videos:-
Overall:63%StarStarStarStar
Rank:872
 
very good tool ;)
10 years ago (pooya sabramooz)
70%StarStarStarStar
Thats a good and useful class ;-)
10 years ago (José Filipe Lopes Santos)
70%StarStarStarStar