2

The SiteMenu Class does not provide any method for getting the menu title column from table *_menu_types. However that field is editable in the admin section (com_menus section, field 'title').

Is there another way than querying the database to retrieve this field (as encoded in cpanel) ?

If not, does anyone have a sample code with db query ?

Thanks !

2

You can get the current menu item alias like so:

$alias  = JFactory::getApplication()->getMenu()->getActive()->alias;

Update:

$active = JFactory::getApplication()->getMenu()->getActive();
var_dump($active);

or

//(int)$id - the actual itemid you want to get;  

$specificMenuItem = JFactory::getApplication()->getMenu()->getItem($id);
var_dump($specificMenuItem);

See: JMenu API

| improve this answer | |
  • Sorry, I was wrong about the table ... updating the question – Cédric Françoys Nov 22 '17 at 11:17
  • @CédricFrançoys : Check answer - $active = JFactory::getApplication()->getMenu()->getActive(); var_dump($active); – FFrewin Nov 22 '17 at 11:19
  • Well thank you, but what I need to achieve is not retrieve the menu item but the menu type to which it belongs, and more precisely the title of that manu type (which, in my case, is 'Main menu') – Cédric Françoys Nov 22 '17 at 11:53
  • @CédricFrançoys - yes I see it now. – FFrewin Nov 22 '17 at 13:55
2

Just in case it helps anyone, this is how I achieved it:

$menu = $app->getMenu();
$active_item = $menu->getActive();

$loader = function ($menu_type) {
    $db = \JFactory::getDbo();
    $result = null;
    $query = $db->getQuery(true)
        ->select('m.id, m.menutype, m.title, m.description')
        ->where("m.menutype = '{$menu_type}'")
        ->from('#__menu_types AS m');
    $db->setQuery($query);
    $list = $db->loadObjectList();
    if(count($list)) $result = array_shift($list);
    return $result;
};

$menu = $loader($active_item->menutype);
$menu_title = $menu->title;
| improve this answer | |

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.