[eluser]crises[/eluser]
I finally found a way of doing a collapsible tree menu from data stored in this way (in my case categories of products for an online catalog). But now i would like to know if this solution is efficient.
I think you got the idea, nothing strange Then i want a menu that firstly shows only the Main Categories, and then if i click in Main Category 1 for example it shows ONLY the first two childs of Main Category (Subcat 1 and Subcat 2). Then if i click in Subcat 2 the menu should show me the childs of Main Category 1 plus childs of Subcat 2. And so on, usual menu as shown in many websites.
To the point. In my catalog controller:
Code:
function category($current_category_url = null, $page=null)
{
/*Rest of stuf*/
$current_category = $this->Catalog_model->get_current_category($current_category_url);//Array with all data of the current category
$root = $this->MPTtree->get_root();
$main_categories = $this->MPTtree->get_children($root['lft'], $root['rgt']);//only Main Categories, without their childrens
$data['menu'] = $this->Catalog_model->do_menu($main_categories, $current_category);
function check_parents($category, $parents_current_category)
{
foreach($parents_current_category as $parent)
{
if ($category['name'] == $parent['name'] && $parent['name'] != 'Root') //Name of root node in tree
{
$current_parent = $parent;
return $current_parent;
exit;
}
}
}
Functions do_menu() and do_submenu() are esentially the same, but as i want different <ul> class i had to make two functions. If you dont need it you can only use one function. Well the code is not as simple as i would like, but at least is working. Now the question again: it is efficient enought? ty