PHP Classes
elePHPant
Icontem

PHP Array Menu List: Create a nested menu from an array with list items

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-03-27 (4 years ago) RSS 2.0 feedNot enough user ratingsTotal: 269 All time: 7,540 This week: 233Up
Version License PHP version Categories
array-menu 1.0.0BSD License5.4HTML, PHP 5, Content management
Description Author

This class can create a nested menu from an array with list items.

It takes as parameter an associative array that defines a structure of menus and sub-menus.

Each menu item may have a label, a link to a given URL and an eventual sub-menu with its own set of items.

The class generates HTML to display the menu as a nested list of items.

  Performance   Level  
Name: William Tabata <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: 30
All time rank: 3789306 in Brazil Brazil
Week rank: 876 Up50 in Brazil Brazil Up

 

Details

arraymenu

Simple control to create a menu

Example 1

$array_simple = [
    'home' => [
        'name' => 'Label for Home',
        'link' => '#',
    ],
    [ /<< see, here don't have key. no matter. just for help u/
        'name' => 'Label for Contact'
    ],
];

$menu = new MenuController($array_simple);
echo $menu->start()->show();

Example 2

$array_level_one = [
    'home' => [
        'name' => 'Label for Home',
        'link' => '#',
    ],
    'contact' => [
        'name' => 'Label for Contact',
        'link' => '#',
    ],
    'sitemap' => [
        'name' => 'Label for Sitemap',
        'link' => '#',
    ],
    'products' => [
        'name' => 'Label for Products',
        'link' => '#',
        'level' => [
            [
                'name' => 'Label for Man (into Producst)',
                'link' => '#',
            ],
            [
                'name' => 'Label for Woman (into Producst)',
                'link' => '#',
            ],
        ]
    ]
];

$menu_b = new MenuController($array_level_one);
$menu_b->setInit("ul class='my_class class_for_ul'");
$menu_b->setItem("li class='my_class_for_item other'");
echo $menu_b->start()->show();

Example 3

$array_level_two = [
    'home' => [
        'name' => 'Label for Home',
        'link' => '#'
    ],
    'contact' => [
        'name' => 'Label for Contact',
        'link' => '#'
    ],
    'sitemap' => [
        'name' => 'Label for Sitemap',
        'link' => '#'
    ],
    'products' => [
        'name' => 'Label for Products',
        'link' => '#',
        'level' => [
            'product_man' => [
                'name' => 'Label for Man (into Producst)',
                'link' => '#',
                'level' => [
                    'product_man_shoes' => [
                        'name' => 'Label for Shoes  (into Man)',
                        'link' => '#',
                    ],
                    'product_man_belt' => [
                        'name' => 'Label for Belt (into Man)',
                        'link' => '#',
                    ],
                ]
            ],
            'produtc_woman' => [
                'name' => 'Label for Woman (into Producst)',
                'link' => '#',
                'level' => [
                    'product_woman_dress' => [
                        'name' => 'Label for Dress  (into Woman)',
                        'link' => '#',
                    ],
                    'product_woman_pantuhose' => [
                        'name' => 'Label for Pantyhose (into Woman)',
                        'link' => '#',
                    ],
                ]
            ],
        ]
    ]
];

$menu_c = new MenuController($array_level_two);
$menu_c->setInit("ol");
echo $menu_c->start()->show();
  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file README.md Doc. README

  Files folder image Files  /  src  
File Role Description
Files folder imageController (1 file)

  Files folder image Files  /  src  /  Controller  
File Role Description
  Plain text file MenuController.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:269
This week:0
All time:7,540
This week:233Up