PHOCOA PHP Framework

YUI Menu Examples

YUI Menu provides Horizontal (MenuBar), Vertical (Menu), and Context (ContextMenu) menu systems via semantic HTML markup, CSS, and Javascript.

PHOCOA makes it easy to build Menu and MenuBars (ContextMenu coming soon) for your application. All you have to do is provide the data.

PHOCOA supports multiple ways of defining the menu structure. Click the links to see the same menu implemented with three different techniques:

Building a YUI Menu from an array of objects implementing WFMenuItem

This technique is ideal when your class structure is already arranged hierarchically in the form of your menu structure. All you need to to is implement the WFMenuItem interface and pass an array of the root menu items build your menu.

$menu->setMenuItems($myArray) takes a structure like:

        ->setLabel('Search Engines')
        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('YAHOO')->setLink('') )
        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('Google')->setLink('') )
        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('Ask')->setLink('') ),
        ->setLabel('PHP Sites')
        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('PHP Official Site')->setLink('') )
        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('Frameworks')
                        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('Cake')->setLink('') )
                        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('Symfony')->setLink('') )
                        ->addChild( WFMenuItemBasic::WFMenuItemBasic()->setLabel('PHOCOA')->setLink('') )

Building a YUI Menu from an array of objects implementing WFMenuTreeBuilding and WFMenuItem (without children)

This technique is ideal when your class structure is flattened, but a single field contains the "path" of where that item should be in the menu. To implement this technique, implement the WFMenuItem interface and the WFMenuTreeBuilding interface.

$menu->setMenuItemsMenuPath($myArray) takes a structure like:

    new YUIMenuExample_ClassWithMenuPath('Search Engines/YAHOO', 'YAHOO', ''),
    new YUIMenuExample_ClassWithMenuPath('Search Engines/Google', 'Google', ''),
    new YUIMenuExample_ClassWithMenuPath('Search Engines/Ask', 'Ask', ''),
    new YUIMenuExample_ClassWithMenuPath('PHP Sites/PHP Official Site', 'PHP Sites', ''),
    new YUIMenuExample_ClassWithMenuPath('PHP Sites/Planet PHP', 'Planet PHP', ''),
    new YUIMenuExample_ClassWithMenuPath('PHP Sites/Frameworks/Cake', 'Cake', ''),
    new YUIMenuExample_ClassWithMenuPath('PHP Sites/Frameworks/Symfony', 'Symfony', ''),
    new YUIMenuExample_ClassWithMenuPath('PHP Sites/Frameworks/PHOCOA', 'PHOCOA', '')

Where YUIMenuExample_ClassWithMenuPath implements WFMenuTree and WFMenuTreeBuilding, and converts it into the requisite tree structure, including the creation of any needed interim nodes.

This is handy when you have a flat structure that contains a field containing path-like data (i.e., a/b/c/d). The algorithm for doing the conversion is a little complex, so PHOCOA includes this as a core capability.

Building a YUI Menu from a Nested Associative Array

This technique is ideal for simple cases where you need only build a menu and don't want to have to implement any class structure at all.

$menu->setMenuItemsNestedArray($myArray) takes a structure like:

array('Search Engines' => array('YAHOO' => '',
            'Google' => '',
            'Ask' => ''
        'PHP Sites' => array('PHP Official Site' => '',
            'Planet PHP' => '',
            'Frameworks' => array('Cake' => '',
                'Symfony' => '',
                'PHOCOA' => ''

Where each "key" is the menu item name, and each "value" is either an array of sub-menu items, or the URL for that menu item.



Basic Examples
  Skin Browser
  Regex Tester

AJAX Examples

  (YUI Examples)
  Tree View
  Tab View

Appcelerator Integration
Copyright (c) 2017 Alan Pinstein. All Rights Reserved.