I want to make a multi-level menu, from database. In the database I have these collumns: 'id', 'name', 'parent_id', 'url'. If item has no children, 'parent_id' is set to 0.
I have used this tutorial: Laravel 4 - Eloquent. Infinite children into usable array? , and it works great, this is the result:
- Home
- Register
- Hello
- Login
- Yeah
- Where
- Is
- My
- Mind
The question is: how do I set the required classes, for Zurb Foundation to work? In this case, I would like to only see [Home], then after I click on it [Register] and [Login] should appear, and so on.
The very last function, that prints out HTML is as such:
private function htmlFromArray($array) {
$html = '';
foreach($array as $k=>$v) {
$html .= "<ul>";
$html .= '<li><a href="#">'.$k."</a></li>";
if(count($v) > 0) {
$html .= $this->htmlFromArray($v);
}
$html .= "</ul>";
}
return $html;
}
And this is the example of dropdown menu from the Zurb website:
<a href="#" data-dropdown="drop1">Has Dropdown</a>
<ul id="drop1" class="f-dropdown" data-dropdown-content>
<li><a href="#">This is a link</a></li>
<li><a href="#">This is another</a></li>
<li><a href="#">Yet another</a></li>
</ul>
So my HTML should look like this:
<a href="#" data-dropdown="drop1">Home</a>
<ul id="drop1" class="f-dropdown" data-dropdown-content>
<li><a href="#" data-dropdown="drop2">Register</a></li>
<ul id="drop1" class="f-dropdown" data-dropdown-content>
<li><a href="#">Hello</a></li>
</ul>
<li><a href="#" data-dropdown="drop3">Login</a></li>
<ul id="drop1" class="f-dropdown" data-dropdown-content>
<li><a href="#">Yeah</a></li>
<li><a href="#" data-dropdown="drop4">Where</a></li>
<ul id="drop1" class="f-dropdown" data-dropdown-content>
<li><a href="#">Is</a></li>
</ul>
</ul>
</ul>
And I have no idea, how to achieve this, so any help would be appreciated. Or if anyone has another way of creating dynamic, multilevel menus, please share!