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');
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'/>" : '';
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');
It doesn't work
Try to use this:
$params = $menus->getParams($menuId);
$myParam = $params->get('theParamIwant');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With