Ahhh... passing a handle as an argument. It seems so obvious now. Thanks I have actually already moved things to a helper, which makes more sense anyway. The helper I have will suit my needs fine this time around. It will be easy to wrap tags around the menu elements when I get around to the CSS. Next time I will use the TreeHelper... I'm sure it will save time.
Thanks again. On Aug 12, 12:46 pm, brian <bally.z...@gmail.com> wrote: > Pass a handle to the helper to your function: > > outputMenu($html, $linkTree, $level); > > function outputMenu(&$html, $array, $level) { > > Even better, have a look at Andy Dawson's TreeHelper. I think it's > precisely what you need for this. > > http://bakery.cakephp.org/articles/view/tree-helper-1 > > Let me know if you need help. I've implemented it for an > ACL-controlled menu and it works great. > > > > On Tue, Aug 11, 2009 at 7:02 PM, Josh<joshs.silver...@gmail.com> wrote: > > > Hi, > > > I have the contents of a tree menu stored in a multi-dimensional > > array. The number of dimensions is not fixed, so to turn the array > > into a menu in the View file, I have set up a recurring function. This > > works fine except that I can't call the $html->link() from the > > function. > > > Fatal error: Call to a member function link() on a non-object in... > > > Any ideas? Is there a way to make the link() function global as you do > > a variable? There are some obvious work-arounds such as writing the > > anchor tag without the html helper, or turning the link array into a > > simpler two dimensional array where I can then iterate the link() > > function. However, I am wonder how I might specifically address the > > question of making the html->link() function available to a function > > within a view file. > > > I have a feeling this is either going to be a simple declaration or > > not worth the trouble. Thanks in advance. > > > Here is my code: > > > //array of links > > ////key: link title > > ////value: link location or sub-array > > $linkTree = array( > > 'User Management' => array( > > 'Permissions' => array( > > 'Set Permissions' => '/tools/setPermissions', > > 'Update ACOS' => '/tools/updateacl', > > 'View/Edit Groups' => '/admin/groups' > > ), > > 'User Settings' => '/tools/userSettings', > > 'Users' => array( > > 'List' => '/admin/users', > > 'Add User' => '/admin/users/add' > > ) > > ) > > ); > > > //output menu function > > function outputMenu ($array, $level) { > > global $levelMarker; > > > foreach ($array as $key => $value) { > > if (is_array($value)) { > > echo $level . $key; > > echo '<br>'; > > outputMenu($value, $level . $levelMarker); > > } else { > > echo $html->link("$level$key", $value); > > echo '<br>'; > > } > > } > > echo "<br>"; > > } > > > //output menu settings > > $levelMarker = '-'; > > $level = ''; > > $linkTreeSimple = array(); > > > //output menu > > outputMenu($linkTree, $level); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---