php - Multiple vertical menu from closure table -


i'm looking multiple vertical menu such here. don't want drop menu. i'm using in mysql database typical closure table hierarchy (ancestor/descendant/depth) categories , want render they. parents , childrens database have these methods:

   public function getsubtree($node) {     $tree = $this->connection->query("     select c.*, cc2.ancestor, cc2.descendant, cc.depth             category c         join category_closure cc         on (c.cat_id = cc.descendant)             join category_closure cc2             using (descendant)     cc.ancestor = $node , cc2.depth = 1     order cc.depth, c.cat_id);      return $this->parsesubtree($node, $tree); }  private function parsesubtree($rootid, $nodes) {     // allow direct access node id     $byid = array();      // array of parrents , children     $byparent = array();       foreach ($nodes $node) {         if ($node["cat_id"] != $rootid) {             if (!isset($byparent[$node["ancestor"]])) {                 $byparent[$node["ancestor"]] = array();             }             $byparent[$node["ancestor"]][] = $node["cat_id"];         }         $byid[$node["cat_id"]] = (array) $node;     }      // tree reconstruction     $tree = array();     foreach ($byparent[$rootid] $nodeid) { // root direct children         $tree[] = $this->parsechildren($nodeid, $byid, $byparent);     }      return $tree; }  private function parsechildren($id, $nodes, $parents) {     $tree = $nodes[$id];      $tree["children"] = array();     if (isset($parents[$id])) {         foreach ($parents[$id] $nodeid) {             $tree["children"][] = $this->parsechildren($nodeid, $nodes, $parents);         }     }      return $tree; } 

in presenter have just:

$this->template->categories = $this->category->getsubtree(1); 

and because i'm using nette framework, i'm using latte template engine, such similar smarty. render categories parents , childrens have this:

    <ul class="tree">     {block #categories}         {foreach $categories $node}             <li>                 <span">{$node["name"]}</span>                 <ul n:if="count($node['children'])">                     {include #categories, 'categories' => $node["children"]}                 </ul>             </li>         {/foreach}     {/block} </ul> 

my biggest problem how make css style if want 3 , more level menu. if selected category subcategories shown , categories hide. when picked subcategories showing subcategories , subcategories hide , on. advance , i'm sorry english. hope know mean.

if understand want drop-down menu. alignment vertical guess. subcategories, should render under category or beside? understand rest should remain visible.


Comments