Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

blackfire49's avatar

Need help with my Menu

Hey guys

First of it is my first time working with a Framework and a Template System.

I want to create a menu but right now i don't know how i could do it.

In the Template i want it to look like this


<div id='menu">
    <div class="menuHead"> {{ $menuHead }}</div>
    <div class="menuCount"> {{ $menuCont }} </div>
</div>

Right now i call it like this MenuHandler::Buildmenu('1') (1 is the left side and 2 the rightside of the homepage menubar)

so now i want to have it loop all inside the menu div do that it looks like this

Menu -> Links -> Downloads Menu2 -> News -> Forum

but i dont know how i could do this

right now my code looks like this


public static function BuildMenu($menu) {
        $men = "<div id='menuWrapper'>";

        $x = null;
        foreach($menu as $k):
            if($k->cname !== $x) {

                $men .= '<div class="menuHead">'.$k->cname.'</div>';
                $x = $k->cname;
            }
            if($k->was != "box") {
                if($k->name != ""):
                    $men .= "<div class='menuCont'><a href='/".$k->url."'><li>".$k->name."</li></a></div>";

                endif;
            } else {
                $men .= view('sections.boxes.'.$k->name);
            }

        endforeach;
        $men .= "<div>";
        return $men;
    }

This works but is not how i would like it to be maybe u can help me

0 likes
3 replies
blackfire49's avatar

So now i have it like this: ( Just testing in php befor using blade)

    use App\MenuModdel;
    $data = MenuModdel::getMenu(1);
    $x = null;
    $menu = "";
    foreach($data as $item):
        if($item->cat !== $x):
            echo $item->name;
            $x = $item->cat;
        endif;
    endforeach;
?>

But for some reason if i have a menu item what goes to the same Menucat

this Cat will be shown 2 times like this

  • Menu
    • Links
  • Clan menu
    • teams
  • Menu Download

but it sould look like this

  • Menu
    • Links
    • Downloads
  • Clan menu
    • Teams

Need help

Cronix's avatar

It's probably due to the order that you receive the data. How are you ordering it in your getMenu() query? Looks like it should be

->orderBy('cat', 'asc')
->orderBy('name', 'asc')
blackfire49's avatar

I order it by catpos for ordering the Categorys and menupos for the menu urls

Ok now i think i now where it goes wrong

first he will load Menu because it is the first entry then Clan Menu the 2 and them Menu again so $x will be clan so he shows menu again because $x isn't menu.

But now i don't have any idee how to slove this

Maybe u?

Please or to participate in this conversation.