Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla : how to get the url of a specific Menu itemID?

Tags:

url

php

menu

joomla

Friends a newbie question.........I need help in getting the URL of a specific Menu itemID. The situation is like this:

I am running Joomla and asking for a user to input for a menu ID and choose a layout for that menu ID.

I want to do something else with this URL of the Menu itemID.

How can I get the URL of this Menu itemID provided by the user?

For Example if the user input is liek $this->get ('menulayoutid'>; and he inputs and ID of 54 then how do I get the URL for Menu ID 54.

Please note: I want to get this URL from within my PHP file and not in the browser so that I can use the value of that URL for some other purpose.

Kindly help.

like image 500
Vikram Rao Avatar asked Dec 25 '10 07:12

Vikram Rao


Video Answer


2 Answers

$itemid = JRequest::getVar('Itemid');
$application = JFactory::getApplication();
$menu = $application->getMenu();
$item = $menu->getItem($itemid);
$link = new JURI($item->link);
$link->setVar('ItemId', $itemid);

Source: http://forum.joomla.org/viewtopic.php?p=1836005

like image 69
moinudin Avatar answered Nov 24 '22 19:11

moinudin


However, we get the Itemid from anywhere (user input, from our own developed module using the "menu item" field type in the xml file as described in the Joomla Docs - Standard form field types)

// get the menuItemId from wherever...
// as described above or as in other posts here and do whatever with that!
$menuItemId = 'fromWherever'; // as an example "107";

// build the link to the menuItemId is just easy and simple
$url = JRoute::_('index.php?Itemid=' . $menuItemId);

i think if we need only a link to a specific menu id, this is the best solution, because we have absolutely less requests and a clean code

this works also in Joomla 3.0, 3.1

like image 39
Lahmizzar Avatar answered Nov 24 '22 21:11

Lahmizzar