How to get menu item id in a plugin in 1.7?

709 views
Skip to first unread message

Brian Tyndall

unread,
Sep 19, 2011, 4:45:36 PM9/19/11
to Joomla! General Development

Hi,

I have been trying out various methods that i have found on the web,
and all of these return the itemid of the active menu item as null.

I have done a var dump of the Jmenusite object and the parameter is
there, its just that none of the techniques i have done have worked. I
have tried this on two different 1.7 sites.

Here are the methods that havent worked so far:

Code:
$itemid = JSite::getMenu()->getActive()->id;


Code:
$application = JFactory::getApplication();
$menu = $application->getMenu();
$item = $menu->getItem( ID );


Code:
$menu = & JSite::getMenu();
$item = $menu->getActive();
$id=$item->itemid;


Code:
$menuitemid    = JRequest::getVar( 'Itemid' );


All of these return a null result for the item id.

Does anyone have the correct way to get the item id please?

Mike Smith

unread,
Sep 19, 2011, 4:48:58 PM9/19/11
to joomla-de...@googlegroups.com
Might be of help.....

Mike


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.


Matt Thomas

unread,
Sep 19, 2011, 5:09:31 PM9/19/11
to joomla-de...@googlegroups.com
Have you tired:

$itemid = JRequest::getInt('Itemid', 0);

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain

Soheil Novinfard

unread,
Sep 2, 2012, 4:13:20 AM9/2/12
to joomla-de...@googlegroups.com
Unfurtunately this is true and I think this is bug of Joomla! .

You can see the related post too:

No one can solve this, because it can't be solved.

I have tried to load menu parameters from external css files and correctly loading platform and what is essential for that. But in case that SEF is on, Itemid can't be reached in any way. In the first message of this issue, all of possible ways that I have tried too, is mentioned by brian.

Any help?

Thanks
Novinfard

elin

unread,
Sep 2, 2012, 8:14:12 AM9/2/12
to joomla-de...@googlegroups.com
The question combined with the forum discussion is a bit confusing. Are you trying to get the Itemid of the current page? Or are you trying to get the itemId of pages linked in the module? 
Matt's answer will give you the Itemid of the current page (assuming it has one). So I am assuming that is not what you want  (although using JInput is the new way).

The forum discussion mentions something about the default template always displaying which makes it sound like you want the Itemid of the pages that are linked from the module (not from the current page). Again it's confusing because you say it is a menu module and by definition links from the menu table will always have an itemid. But I think the main thing is that you want to use routing for your links so that the reverse lookup through the menu table that checks for menu items that match the request takes place.
You could look for example in the helpers for any of the articles modules.

Elin
Reply all
Reply to author
Forward
0 new messages