how to get joomla menu object based on name?
This question is bit specific to joomla.
I know if with the code $menu = &JSite::getMenu()
I can get the reference object of the complete menu. But how can i get a specif menu based on the name?
My Scenario : I have footer-menu with items : home | about us | rules | privacy policy.
I need to display links to two menu items Rules and privacy policy in a component. I cannot hard code the links, as the itemid would be different in development and production 开发者_JAVA百科environment.
Do we have some workaround like $menu = &JSite::getMenu()->get('footer-menu')->getMenuItem('rules');
which can give me refrence object to a particular menu item, from which I can create my links for that particular article.
Thanks, Tanmay
As far as I know, there isn't a built-in way to do this. But I feel your pain.
Here's an adaptation of a function I built before. It's not recursive, so you'll only get one level deep in a menu hierarchy, but that was enough for me.
function getMenuItems( $parentAlias ) {
$db =& JFactory::getDBO();
$sql = 'SELECT * FROM #__menu WHERE parent in ' .
'(SELECT id FROM #__menu WHERE alias='.$db->Quote($parentAlias).') '.
'AND published=1 ORDER BY ordering';
$db->setQuery($sql);
$results = $db->loadObjectList();
}
Let me know if this works for you.
Method #1:
$menu = & JSite::getMenu();
$item = $menu->getItems('link', 'index.php?option=com_content&view=article&id=1', true);
Method #2:
$menu = & JSite::getMenu();
$item = $menu->getItems('alias', 'rules', true);
精彩评论