You must be logged in to view profiles.

MenuHelper

By Alexander Morland (alkemann)
A tool for building and rendering lists of links and elements. This helper will let you build up static and context sensitive links in your views and then render them all as part of the layout. It is powerful enough to do multiple, nested lists. Created for the purpose of main, sub and context sensitive menues, this helper can also be used as an html UL generator.

Installation and requirements

  • Copy code to a file app/views/helpers/menu.php
  • add 'Menu' to AppController's $helpers property

To understand how this helper works there are two important concepts. Firstly, in a single run of cakephp, only one instance of any helper is used. There for we can temporarily "store" information in it (as a property) between views, elements and layouts. In the most common use of this helper, links are created in the view and in elements and then the layout renders them. The reason why this works is the second important concept; the layout is rendered after the view. Therefore we can add to the list of urls in when the layout is rendered, the menu helper already know all that it is to render.

Page 2: Examples

Comments 934

CakePHP Team Comments Author Comments
 

Comment

1 Array-keys must be string

Hopefully this save somebody from wasting some hours: index keys must be strings. For example key 'branch1' will work but key '1' will not.

A working example of a 3-level menu with keys:


$menu->add('tree', array('root1', array('controller'=>'root', 'action'=>'view', 1)));
$menu->add(array('tree', 'branch1'), array('branch1name', array('controller'=>'branch', 'action'=>'view', 1)));
$menu->add('tree', array('root2', array('controller'=>'root', 'action'=>'view', 2)));
$menu->add(array('tree', 'branch2'), array('branch2name', array('controller'=>'branch', 'action'=>'view', 2)));
$menu->add(array('tree', 'branch3'), array('branch3name', array('controller'=>'branch', 'action'=>'view', 3)));
$menu->add(array('tree', 'branch2', 'leaf1'), array('leaf1name', array('controller'=>'leaf', 'action'=>'view', 1)));
$menu->add(array('tree', 'branch2', 'leaf2'), array('leaf2name', array('controller'=>'leaf', 'action'=>'view', 2)));
echo $menu->generate('tree');


Great Helper once you get to know it !
Posted Sep 28, 2009 by Bravo Kernel
 

Comment

2 Lol what a title =)

Best medication online Buy Differin Online Best pills online Buy Ventolin Best drugs online Buy norvasc Best meds online Buy Citalopram Best meds online acheter kamagra Best meds online kaufen cialis Best drugs online Buy Crestor Best meds online Buy Trazodone Online Best pharmacy online Buy Norvasc Online Best pharmacy online Buy Citalopram Online Best pills online Buy Prednisone Online
Posted Mar 18, 2010 by asdfasdfww