开发者

joomla component menu itemID

开发者 https://www.devze.com 2023-01-26 06:39 出处:网络
If my component is listed under the menu and assign modules to that menu if the link don\'t contain e.g. itemID=63 than module is not showing.

If my component is listed under the menu and assign modules to that menu if the link don't contain e.g. itemID=63 than module is not showing.

Is there 开发者_StackOverflow社区a way to automatic add ItemId to each link and redirect inside the component?


In the code that generates the links in the component you need to append the ItemId to the url. You can get the ItemId using:

$itemid = JRequest::getint( 'Itemid' );

So you would use this in such a fashion (as an example):

$link = JRoute::_('index.php?option=com_component&task=list&Itemid='.$itemid);

This var will exist once the menu item has been clicked. It then needs to be carried through each view in the component if the views sit in a hierarchical fashion where one view links to the next.

[EDIT]

You could create a helper function that for the example above, automatically adds the ItemId to every link you generate e.g.

function genLink($link) {
    return JRoute::_($link.'&Itemid='.JRequest::getint( 'Itemid' ));
}


I my experience this problem arises in cases when you have a module (ex. virtuemart product list) placed somewhere NOT in the section where your link should bring to. Let's say you have VM(com_virtuemart) set up in your menu with Itemid===731 and you insert a product list module in home page(com_content). When you click on the product which brings you to the product page you would expect the module to set up the link in such a way that your VM Itemid is included in the link ([linkl]&Itemid=731) - but in most cases it does not happen, your Itemid is not added to the url.

Also, you cannot always expect (like in this case) to have the correct Itemid in your url params. so JRequest::getint( 'Itemid' ) stuff will not work as expected.

I do not know the reason why JRoute::_ method (it could be easily done with an extra param "$searchForItemid") does not search for your Itemid in the menu table WHEN YOU ARE NOT IN THE COMPONENT! This is to say that if you put the same product list module visible in the VM front page(com_virtuemart) you will see that the Itemid appears on your links. But in most cases that module needs to be somewhere else.

This is still the case w\ J!2.5.

I do not have a solution for you but i can tell you how i overcome this.

Obviously, you could open up the module and hardcode the Itemid. This, in Italy is called "PORCATA" (translation: pig style coding) and I really advise against it for obvious reasons

What I do is I use the language override (J!2.5 - Language Manager: Language Overrides), register an override like VM_ITEMID===731 and then in the module i create a custom template and change the link from:

JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id...')

to:

JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id...'.'&Itemid='.JText::_("VM_ITEMID"))

I repeat, this is not a solution to the problem and this should, IMHO, be taken care of by the core but it works and this way you have the possibility to change the Itemid bound to the component. hope this helps


When you need to get your active menu item ID in Joomla to display some specific content for only that menu item or just to show the ID of the menu item, insert the following code where you wish to display the active menu item ID:

<?php 
$currentMenuId = JSite::getMenu()->getActive()->id ;
echo "Your menu item ID is: $currentMenuId"; 
?>


This is old but in case anyone needs it here's the answer. Retrieve your itemid from parameters:

<!--ITEMID FROM MENU-->
<?
$params =JComponentHelper::getParams( 'com_lobotoradio' );
$itemid = $params->get('itemid');
?>
<!--END ITEMID FROM MENU-->

And then print it wherever you need it:

<?php echo $itemid; ?>

Worst case scenario, use this hack:

<?php 
$itemid = X;
echo $itemid;
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消