CMenu with Module sub menus

Hi Guys,

Quick one for someone out there ::)

I want to build a dynamic menu including menu items from modules if available. I want to maintain the module menus at the module level but want to know whats the best way to present the data to the main menu. Ive had a look about and cant figure out should it be:

  • A Widget (seems unlikely as this seems more related to displaying data)

  • CArrayDataProvider, seems a bit more likely but not 100% sure if this is a dataprovider im looking for

  • Just within the module class as a method? (how do i call it then)

  • As a standalone component extending nothing? (how do i call it then)

Hope this makes sense?


Main Menu




             array('label'=>'Home', 'url'=>array('/site/index')), 

             (isModuleInstalled) ? module->getMenu() : array(),




then in the module something like:


public getMenu() {

    return array(

        array('label'=>'Module Menu 1', 'url'=>array('/site/index')), 



Well you can have access to the installed modules with this, and then you can check if they are enabled or not and call the getMenu method, you can also create an interface which all modules should implement in order to ensure the method is always present and avoid any problems.