HTML_Menu - Menu Array

From: Date: Mon, 07 Jun 2004 12:47:07 +0000
Subject: HTML_Menu - Menu Array
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-12964@lists.php.net to get a copy of this message
I've been struggling with getting this package working. My problem is getting my data into the class. The documentation says: * 1 - Projects * 11 - Projects => PHPDoc * 12 - Projects => Forms * 2 - Stuff * * you need the array: * * $menu = array( * 1 => array( * 'title' => 'Projects', * 'url' => '/projects/index.php', * 'sub' => array( * 11 => array( * 'title' => 'PHPDoc', * ... * ), * 12 => array( ... ), * ) * ), * 2 => array( 'title' => 'Stuff', 'url' => '/stuff/index.php' ) I have data I have retrieved from a table which is in this format: ID TITLE URL PARENT which is saved into an array called $all_links, and I'm trying to get it into a multidimensional array as described in the document. I'm getting quite a headache trying to work out how. Here is what I have so far: function get_menu_tree($id = 0, $use_parent_id = 0, $y=0) { $copy_links = $this->all_links; reset($copy_links); for ($x=0; $x<sizeof($copy_links); $x++) { if ($copy_links[$x]['parent'] == $id) { if ($use_parent_id==0) { $no = $x+1; } else { $y++; $no = $use_parent_id . $y; } $children[$no]["id"] = $copy_links[$x]["id"]; $children[$no]["title"] = $copy_links[$x]["title"]; $children[$no]["url"] = $copy_links[$x]["url"]; if ($this->get_type($copy_links[$x]["id"])) { $children[$no]["sub"] = $this->get_menu_tree($copy_links[$x]["id"], $no, $y); } } } return $children; } // end get_menu_tree It only works well to the second level and then the numbering stuffs up again. Urgh. I'm sure I'm probably missing something fundamental. Also, doesn't the format of the $menu array limit each level to only 9 items? BTW the reason I chose this class is I wanted to render the menus into <ul> lists to formatting via CSS, and I also use the Sigma templating system, so it seemed a good fit. Leonie (very tired and headachy)

« previous php.pear.general (#12964) next »