Joomla获取菜单项ID

时间:2013-09-28 13:21:45

标签: joomla joomla2.5

我有一个包含简单付款方式的组件。我只想获取当前菜单项ID。我已经尝试了几件事来获得身份。

    //get the active menu item id
    $app = JFactory::getApplication();
    $menu   = $app->getMenu();
    $active   = $menu->getActive();
    $activeId = $active->id;
    JLog::add('active id is: '.$activeId); //I get nothing returned

    $currentMenuId = JSite::getMenu()->getActive()->id ;
    JLog::add('menu id is: '.$currentMenuId); //I get nothing returned

    //try to see what the current url is
    $currenturl = JURI::current();
    JLog::add('current url is: '.$currenturl); //I get mysite.com/index.php

我在我的插件中使用$activeId代码没有问题,但它在我的组件中不起作用。我错过了什么?

1 个答案:

答案 0 :(得分:15)

$app = JFactory::getApplication();
$menu = $app->getMenu()->getActive()->id;
echo $menu;

希望这就是你要找的东西