For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > September 2007 > Can I display 2 different DBNested Set/HTML_Menus on the same page?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can I display 2 different DBNested Set/HTML_Menus on the same page?
Mark Reynolds

2007-09-20, 7:03 pm

I'm displaying 2 menus on the one page using DBNestedSet and HTML_Menu

The first menu 'urhere' uses getAllNodes()
but the second menu just uses getBranch()

I can't put my finger on it, but once the getAllnodes urhere menu is
displayed the data somehow carries over and populates the array of the
getBranch tree menu with all nodes instead of just the sub branch. This is
even though I go through the DBNested process again.

It looks like I somehow need to reset the data once the first menu has been
displayed. Does anyone have any suggestions on the solution?? I've done
quite a bit of trial and error, but nothing seems to work.

Thanks

_______BEGIN CODE FOR URHERE getAllNodes_______________

// Fetch the entire tree into an array
$data = $nestedSet->getAllNodes(true);

// Create the links
foreach ($data as $id => $node) {
$data[$id]['url'] = $_SERVER['PHP_SELF'].'?nodeID=' . $node['id'] .
'&nodename=' . $node['name'];
}

// Send HTML_Menu the structure, title and URL for the items in our tree
$params = array(
'structure' => $data,
'titleField' => 'name',
'urlField' => 'url');

// Create the output driver object
$output =& DB_NestedSet_Output::factory($params, 'Menu');

// Fetch the menu array
$structure = $output->returnStructure();

// We'll create the new HTML_Menu object, using the urhere display driver
$menu = & new HTML_Menu($structure, 'urhere');

// Create the current URL and send it to HTML_Menu
$currentUrl = $_SERVER['PHP_SELF'].'?nodeID=' . $_GET['nodeID'] .
'&nodename=' . $_GET['nodename'];

$menu->forceCurrentUrl($currentUrl);

// Show the menu
echo $menu->show();

_______END CODE FOR URHERE_______________

_______BEGIN CODE FOR TREE getBranch_______________

$data = $nestedSet->getBranch(1, true);

// Create the links
foreach ($data as $id => $node) {
$data[$id]['url'] = $_SERVER['PHP_SELF'].'?nodeID=' . $node['id'] .
'&nodename=' . filename_from_db_to_url($node['name']);
}

// Send HTML_Menu the structure, title and URL for the items in our tree
$params = array(
'structure' => $data,
'titleField' => 'name',
'urlField' => 'url');

// Create the output driver object
$output =& DB_NestedSet_Output::factory($params, 'Menu');

// Fetch the menu array
$structure = $output->returnStructure();

$structure = & new HTML_Menu($structure);

$renderer =& new HTML_Menu_DirectTreeRenderer;

// Create the current URL and send it to HTML_Menu
$currentUrl = $_SERVER['PHP_SELF'].'?nodeID=' . $_GET['nodeID'] .
'&nodename=' . filename_from_db_to_url($_GET['nodename'
]);

$structure->forceCurrentUrl($currentUrl);

$structure->render($renderer, 'tree');

// Output the menu
echo '<div id="mainleftnav" class="leftbox">'.$renderer->toHtml()."</div>";

_______END CODE FOR TREE_______________
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com