JHtmlMenu/menuitems
From Joomla! Documentation
< API16:JHtmlMenu
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Returns an array of menu items groups by menu.
Template:Description:JHtmlMenu/menuitems
Syntax[edit]
static menuitems($config=array())
Parameter Name | Default Value | Description |
---|---|---|
$config | array() | An array of configuration options. |
Returns[edit]
array
Defined in[edit]
libraries/joomla/html/html/menu.php
Importing[edit]
jimport( 'joomla.html.html.menu' );
Source Body[edit]
public static function menuitems($config = array())
{
if (empty(self::$items))
{
$db = JFactory::getDbo();
$db->setQuery(
'SELECT menutype As value, title As text' .
' FROM #__menu_types' .
' ORDER BY title'
);
$menus = $db->loadObjectList();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title As text, a.level, a.menutype');
$query->from('#__menu AS a');
$query->where('a.parent_id > 0');
$query->where('a.type <> '.$db->quote('url'));
// Filter on the published state
if (isset($config['published'])) {
$query->where('a.published = '.(int) $config['published']);
}
$query->order('a.lft');
$db->setQuery($query);
$items = $db->loadObjectList();
// Collate menu items based on menutype
$lookup = array();
foreach ($items as &$item) {
if (!isset($lookup[$item->menutype])) {
$lookup[$item->menutype] = array();
}
$lookup[$item->menutype][] = &$item;
$item->text = str_repeat('- ',$item->level).$item->text;
}
self::$items = array();
foreach ($menus as &$menu) {
self::$items[] = JHtml::_('select.optgroup', $menu->text);
self::$items[] = JHtml::_('select.option', $menu->value.'.0', JText::_('COM_MENUS_ADD_TO_THIS_MENU'));
if (isset($lookup[$menu->value])) {
foreach ($lookup[$menu->value] as &$item) {
self::$items[] = JHtml::_('select.option', $menu->value.'.'.$item->value, $item->text);
}
}
}
}
return self::$items;
}
[Edit See Also] Template:SeeAlso:JHtmlMenu/menuitems
Examples[edit]
<CodeExamplesForm />