0

I am trying to get the current itemid of an especific menu which calls a custom component.

I had a custom component called on the menu with the url /something.

Inside of the site model of my component I have this in my constructor:

    $jinput = JFactory::getApplication('site')->input; 
    $uriQuery=$jinput->getArray();
    //var_dump($uriQuery);
    $itemid=$uriQuery['Itemid'];
    echo $itemid; // it gives me a random id = 234

If I create another menu with url /otherthing and call the same custom component, with the same model, the echo $itemid returns a differen random id = 132.

So my question is: Where does the Id comes from?. It comes from the url?. From the menú that I create?.

Thanks!

1 Answer 1

3

If I understand it right. You wan't to get the ID of the current active menu.

Theres a great example on this forum: https://forum.joomla.org/viewtopic.php?t=642224

Here's the code part:

// get application
$app    = JFactory::getApplication();

// get menu
$menu   = $app->getMenu();

// get active menu id
$activeId = $menu->getActive()->id;

// get active menu
$active = $menu->getActive();

// get active menu id
$activeId = $active->id;

// get active parent id 
$currentMenuParent = $active->parent_id;

// get active menu item title
$menutitle = $active->title;

// get menu item by id
$otherMenuItem = $menu->getItem( $menuID );

// get other menu item title
$title = $otherMenuItem->title;

And what you want to do is this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.