Getting menu options from Joomla

I am trying to get options from a menu table in Joomla. What I have below works in the sense that it returns parameters.

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

However, it returns them in plain text, as if I had just requested a column and returned the contents of params.

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

 $myParam = $item->getParams('theParamIwant'); 
+4
source share
7 answers

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

  $ item = $ menu-> getItem ($ menuId);
 $ params = new JParameter ($ item-> params);
 $ myParam = $ params-> get ('theParamIwant');
+6
source

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

  $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 is full, 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 the tertiary statement:

 $menuimg = $params->get('menu_image') echo strlen($menuimg) ? "<img src='$menuimg'/>" : ''; 
+11
source

Does not work

Try using this:

 $params = $menus->getParams($menuId); $myParam = $params->get('theParamIwant'); 
+2
source
 $app = JFactory::getApplication(); $params = $app->getParams(); $yourParameter = $params->get('YOURPARAMETERNAME'); 
0
source
  ($currentMenuId = JSite::getMenu()->getActive()->id ; // `enter code here` $document =& JFactory::getDocument(); // `enter code here` $app = JFactory::getApplication(); // `enter code here` $menuitem = $app->getMenu()->getItem($currentMenuId); // or get item by ID `enter code here` $params = $menuitem->params; // get the params `enter code here` $params->get('menu-meta_keywords'); if($document->description == '') // 116 is the ID number of the menu pointing to the component `enter code here` { $this->setMetaData( 'description', $params->get('menu-meta_description') ); $this->setMetaData( 'keywords', $params->get('menu-meta_keywords') ); } else { // do nothing }) 
0
source

Work in 3.5.1

 $app = JFactory::getApplication(); $currentMenuId = JSite::getMenu()->getActive()->id; $menuitem = $app->getMenu()->getItem($currentMenuId); $params = $menuitem->params; echo $params['menu_image']; 

Shows an image of a menu item

0
source

JParameter is deprecated in Joomla 2.5, so to get Kevin code to work, add

jimport( 'joomla.html.parameter' ) before ie

 jimport( 'joomla.html.parameter' ); $item = $menu->getItem($menuId); $params = new JParameter($item->params); $myParam = $params->get('theParamIwant'); 
-1
source

Source: https://habr.com/ru/post/1339397/


All Articles