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