3

我有一个包含简单付款表格的组件。我只想获取当前的菜单项 ID。我已经尝试了几件事来获取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代码没有问题,但它在我的组件中不起作用。我错过了什么?

4

1 回答 1

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

希望这就是你要找的

于 2013-09-28T13:24:49.593 回答