Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Menu Parameters from Joomla

Tags:

php

joomla

I'm trying to get parameters from the menu table in Joomla. What I have below is working in the sense that it is returning the parameters.

 $menu =   &JSite::getMenu();
 $item =  $menu->getItem($menuId)->params;
 print $items;

However, It's returning them in plain text, as if I had just queried the column and returned the params contents.

Can someone tell me how to return this as an Object or Array so that I can use something like:

$myParam = $item->getParams('theParamIwant');
like image 447
tpow Avatar asked Feb 11 '11 18:02

tpow


3 Answers

I think JParameter is obsolete in Joomla! 3.x, so the answer now is something like:

 $app = JFactory::getApplication();
 $menuitem   = $app->getMenu()->getActive(); // get the active item
 $menuitem   = $app->getMenu()->getItem($theid); // or get item by ID
 $params = $menuitem->params; // get the params
 print_r($params); // print all params as overview

You can get the menu_image variable by doing:

 echo $params->get('menu_image');

Or first check if it's filled in and, if it is, echo it:

// using get() with a second parameter makes it fall back to this if nothing is found
$menu_image = $params->get('menu_image', false);
if ($menu_image && strlen($menu_image)) {
   echo "<img src='$menu_image'/>";
}

Or, using a tertiary operator:

$menuimg = $params->get('menu_image')
echo strlen($menuimg) ? "<img src='$menuimg'/>" : '';
like image 72
xaddict Avatar answered Nov 10 '22 12:11

xaddict


You need to use the JParameter class to read the params. Try something like this:

$item = $menu->getItem($menuId);
$params = new JParameter($item->params);
$myParam = $params->get('theParamIwant');
like image 45
Kevin Strong Avatar answered Nov 10 '22 12:11

Kevin Strong


It doesn't work

Try to use this:

$params = $menus->getParams($menuId);
$myParam = $params->get('theParamIwant');
like image 2
denis Avatar answered Nov 10 '22 14:11

denis