Jump to content

Dynamically Created Navigation


Xtremer360

Recommended Posts

I'm trying to take my php output and using the HTML nav structure that is currently there turn it into dynamically generated menu using my result set. Any help on helping me figure out how to correct this.

 

Here's my output.

array(3) {
    [0]=> object(stdClass)#24 (3) {
        ["category_id"]=> string(1) "1"
        ["category_name"]=> string(9) "Dashboard"
        ["category_class"]=> string(9) "dashboard"
    }
    [1]=> object(stdClass)#24 (3) {
        ["category_id"]=> string(1) "2"
        ["category_name"]=> string(5) "Users"
        ["category_class"]=> string(5) "users"
    }
    [2]=> object(stdClass)#24 (3) {
        ["category_id"]=> string(1) "3"
        ["category_name"]=> string(5) "Pages"
        ["category_class"]=> string(5) "pages"
        ["links"]=> array(2) {
            [0]=> object(stdClass)#24 (2) {
                ["item_id"]=> string(1) "1"
                ["item_name"]=> string(5) "Admin Pages"
            [1]=> object(stdClass)#24 (2) {
                ["item_id"]=> string(1) "2"
                ["item_name"]=> string(5) "User Pages"
            }
        }
    }
}

I'm wanting to take my php output and using the HTML code below make a dynamic navigation.

<li class="active"><a href="" class="glyphicons dashboard"><i></i><span>Dashboard</span></a></li>
<li class="hasSubmenu">
    <a href="#menu_character" data-toggle="collapse" class="glyphicons page"><i></i><span>Pages</span><span class="icon-chevron-down"></span></a>
    <ul class="collapse" id="menu_character">
        <!-- Components Submenu Regular Items -->
        <li class=""><a href="">Item 1</a></li>
        <li class=""><a href="">Item 2</a></li>
        <!-- // Components Submenu Regular Items END -->
    </ul>
</li>

This is what I have so far.

<?php 
foreach ($dashboard_menu_categories AS $category)
{
    echo '<li>';
     if (isset($category->links))
     {
         echo '<ul class="collapse" id="menu_'.$category->category_short_name.'">';
         /* Components Submenu Regular Items */
         foreach($category->links AS $item)
         {
             echo '<li class=""><a href="">'.$item->item_name.'</a></li>';
         }
         /* Components Submenu Regular Items END */
         echo '</ul>';
    }
    echo '<a href="" class="glyphicons '.$category->category_class.'"><i></i><span>'.$category->category_name.'</span></a>';
    echo '</li>';
}
?>
Link to comment
https://forums.phpfreaks.com/topic/283976-dynamically-created-navigation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.