3

I'm trying to make a menu module, but I'm kind of stuck. I want the user to be able to select from several menu's, so that he/she can pick one to be displayed on the page.

I tried it this way:

$menu = JFactory::getApplication()->getMenu($params->get('menutype'));

There's a menutype selection option in the module backend, which I refer to in this code, but this didn't work for me. I can tell I'm starting to do things randomly so I figured I'd ask it here.

So, how can I set it so the user can select their prefered menu?

I'm using J! 2.5

  • Once they have picked their menu, does their choice get stored in the database at all for future reference? – Lodder Oct 31 '14 at 9:53
  • A bit confused with what you want to do. You are creating a custom menu module and you want the module to be able to display all the menus that exist (from Menus component), so the admin will to choose the one that he wants this module to use? – FFrewin Oct 31 '14 at 9:59
  • I can't get the module to work with the selected menu that the user selected in the administrator panel of the module--it always keeps refering to mainmenu, and showing items from that, eventhough I want it to refer to, for example, secondmenu, and show the items in that menu. – Hocho Oct 31 '14 at 10:17
  • Sorry for the double comment. Lodder; yes, the choice does get stored in the database under the params. – Hocho Oct 31 '14 at 10:18
0

If I understood right (as on my comment), you want to create a field in your module that will display all the available menus in your site. Joomla provides this type of field (menu) in its standard form fields types.

So in your module's XML, you need to add a menu field like:

<field name="mymenu" type="menu" default="" label="Please select a menu" description="Please select a menu" />
  • Thanks for the quick response, however, I already have this in my XML file. The thing is, I can't get the module to work with the selected menu that the user selected--it always keeps refering to mainmenu, eventhough I want it to refer to, for example, secondmenu. – Hocho Oct 31 '14 at 10:15
  • I see. And what you get if you echo the $params->get('menutype') ? Also, enable error reporting to see if there are any errors. – FFrewin Oct 31 '14 at 10:34
  • it echo's menu-type: mymenu. that's nice :) now how do I use it to load my menu in the module, rather than continuisly using the main menu which I can't seem to change? – Hocho Oct 31 '14 at 10:42
0

ehm, well, lets just say I fixed this issue :) I took the helper file from the standard menu module as delivered by Joomla defaultly in their CMS. This works for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.