tags:

views:

62

answers:

1

Hi,

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 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

A: 

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.

Garrett Bluma
Garrett Bluma, Well at the end I did something bit similar to your implementation, created a function in the model, to get me object for the menu items I want. Thanks for your reply. At least it confirmed that i am not missing a great function of joomla :)
jtanmay