From Joomla! Documentation

< API16:JHtmlAccess

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.


Displays a list of the available user groups.

<! removed transcluded page call, red link never existed >


static usergroup($name, $selected, $attribs= '', $allowAll=true)
Parameter Name Default Value Description
$name The form field name.
$selected The name of the selected section.
$attribs Additional attributes to add to the select field.
$allowAll true True to add "All Groups" option.


string The required HTML for the SELECT tag.

Defined in



jimport( 'joomla.html.html.access' );

Source Body

public static function usergroup($name, $selected, $attribs = '', $allowAll = true)
        $db = &JFactory::getDbo();
                'SELECT a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level' .
                ' FROM #__usergroups AS a' .
                ' LEFT JOIN `#__usergroups` AS b ON a.lft > b.lft AND a.rgt < b.rgt' .
                ' GROUP BY a.id' .
                ' ORDER BY a.lft ASC'
        $options = $db->loadObjectList();

        // Check for a database error.
        if ($db->getErrorNum()) {
                JError::raiseNotice(500, $db->getErrorMsg());
                return null;

        for ($i=0,$n=count($options); $i < $n; $i++) {
                $options[$i]->text = str_repeat('- ',$options[$i]->level).$options[$i]->text;

        // If all usergroups is allowed, push it into the array.
        if ($allowAll) {
                array_unshift($options, JHtml::_('select.option', '', JText::_('JOption_Access_Show_All_Groups')));

        return JHtml::_('select.genericlist', $options, $name,
                        'list.attr' => $attribs,
                        'list.select' => $selected

<! removed transcluded page call, red link never existed >


Code Examples