The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun May 20, 2012 12:58 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Apr 27, 2012 4:30 pm
Posts: 6
Hi
I am new to Joomla. I am using Joomla 2.5. I am trying to get the text of a Active menu item. I tried this code.
$menu = &JSite::getMenu();
$menuItem = $menu->getActive();
print_r("Active Menu ID ".$menuItem->id);

it gives me the id of active menu item. but i want to get the title or text of the active menu item.

Please help..
Thanks in advance ...


Top
 Profile  
 
PostPosted: Mon May 21, 2012 3:25 am 
User avatar
Joomla! Master
Joomla! Master

Joined: Wed Aug 13, 2008 2:57 am
Posts: 22627
Location: Chennai, India
Suggest reviewing code of the extension Amplify title Module (http://extensions.joomla.org/extensions/style-a-design/titles/6515). I believe that the function you looking for is in that module.

_________________
- Ilagnayeru (MIG) Manickam
http://www.eegan.org - helping the poor and underprivileged
educate. empower. enrich.
Support the poor and underprivileged


Top
 Profile  
 
PostPosted: Mon May 21, 2012 6:30 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Apr 27, 2012 4:30 pm
Posts: 6
Dear imanickam
Tons of Thanks for replying.

Actually I figured out myself.
Here is the thing I was looking. I wanted to fetch the title of Active Menu Item. Following is the code to get the text of the Current Menu item clicked.

Code:
/** Getting the Menu ID of Menu was clicked by user **/
$menu    =   &JSite::getMenu();
$id    =   $menu->getActive()->id;

/** Getting the Title of the Menu by using id. **/
$db    = JFactory::getDBO();
$query    = "SELECT title FROM kjs_menu WHERE id = $id";
$db->setQuery($query);
$rows    = $db->loadObjectList();
$itemrow = $rows[0];
$title   =   $itemrow->title;

echo "Menu you have clicked is : ".$title;


I dnt know if there is other easy way to handle it. If anybody know please post it to me.


Top
 Profile  
 
PostPosted: Mon May 21, 2012 6:43 pm 
Joomla! Ace
Joomla! Ace

Joined: Sat Jan 21, 2006 8:42 pm
Posts: 1152
$active = JFactory::getApplication()->getMenu()->getActive();
echo $active->title;

getActive gives back an object if it is able to get an active menu, so the object also include the title.
To make sure you have an object check it before you do any output.


Top
 Profile  
 
PostPosted: Tue May 22, 2012 4:36 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Apr 27, 2012 4:30 pm
Posts: 6
wow wow wow .. :o

Thanks RedEye

it has reduced my code to just two line .. :D :D

Tons of Thanks


Top
 Profile  
 
PostPosted: Tue Aug 21, 2012 8:50 am 
Joomla! Intern
Joomla! Intern

Joined: Thu Nov 05, 2009 6:49 pm
Posts: 83
hello guys.

where do you put this code?? i would like to know that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 



Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group