2013-09-28 98 views
2

我有一個組件具有簡單的付款方式。我只想獲取當前的菜單項ID。我已經嘗試了幾件事情來獲得ID。Joomla獲取菜單項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代碼沒有問題,但它並不在我的組件工作。我錯過了什麼?

回答

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

希望這是你在找什麼

+0

謝謝,但那個是一樣的,我的問題只是把它寫一個不同的方式。無論如何我都試過了,我仍然沒有任何回報。 – Tom

+0

嘗試'var_dump($ menu)'並查看顯示的內容。另外,在付款表格中,URl是否以*/index.php *結尾? – Lodder

+0

'var_dump($ menu)'給出了包括我想要的菜單在內的大列表。該URI沒有index.php。評論的整個URI是'http:// mysite.com/step2bv'。我想獲取step2bv的id或名稱以作進一步處理。 – Tom