Navigation menu and modules

I was after some advice regarding the best way to manage the navigation menu and having different modules. In this project we are working on we are splitting the system into the relevant modules and adding the menu items for options which are specific to the module. However we have an Administration menu which could have options from various modules. Currently I’ve setup an Admin menu in the main Application module and in other modules but the system isn’t merging the navigation arrays into a single menu it is instead rendering multiple “Admin” menus.

Should the Admin menu exist in 1 module or are you able to have a menu with the same name in multiple modules but render it only once?

Our navigation options are defined in the /config/module.config.php

laminas-mvc merges the configuration of all registered modules. So please provide the configuration for your navigation.

@mattG10 In your config file for each module you can provide a top level config key to namespace your menus. Once that is done:

 'navigation' => [
        'static' =>[
            [
                'label' => 'Home',
                'route' => 'home',
                'class' => 'nav-link',
                'order' => '-10',
            ],
            [
                'label' => 'Admin',
                'route' => 'app.admin',
                'class' => 'nav-link',
                'resource' => 'admin',
                'privilege' => 'admin.access',
            ],
        ],
        'admin' => [
            [
                'label' => 'Home',
                'route' => 'home',
                'class' => 'nav-link',
                'order' => '-10',
            ],
            [
                'label' => 'App Settings',
                'route' => 'app.admin',
                'class' => 'nav-link',
                'resource' => 'admin',
                'privilege' => 'admin.access',
            ],
        ],
    ],

the namespaces used there is static and admin. I should point out that I load a layout for non admin routes and a layout for all admin routes as each in my application will contain its own admin area. I then render the menu as follows:

<?php 
                $this->navigation()->setAcl($this->acl);
                $this->navigation()->setRole($this->user->role);
                $this->navigation()->menu()->setUlClass('navbar-nav');
                echo $this->navigation('Laminas\Navigation\Static')->menu();
                ?>`
Of course changing the namespace to admin as like this:
`<?php 
                $this->navigation()->setAcl($this->acl);
                $this->navigation()->setRole($this->user->role);
                $this->navigation()->menu()->setUlClass('navbar-nav');
                echo $this->navigation('Laminas\Navigation\Admin')->menu();
                ?>

I hope it helps. @froschdesign or one of the other pros here can probably give you a better way to do it, but it works for in my use case for the moment.

Hello and welcome to our forums! :smiley:

Unfortunately, we do not know exactly what the problem is. It could be a wrong configuration, because apparently the navigation is not merged correctly.

Your example is correct and corresponds to the example in the documentation:

This can be done via laminas-servicemanager’s delegators. There are two pull requests that show the usage:

@froschdesign I apologize if I caused confusion in the topic there. The code I posted is taken from the examples and works as expected. I posted it as I originally had the same issue as the original poster but got it working. I will definitely check out the pull request and revise accordingly. :slight_smile: