4

I want to new a user group by php, I think there should be an API ready but I just can't find an example code by google. I have the parent group name and ID, and the new group title is ready, what object should I get and how to create the new user group? If there is no API for this, I might just access the #_Usergroups, but I am worry I'll mess uo the lft, rgt columns. If someone could show me, or have any other suggestions, an example cold would be great.

1 Answer 1

6

You can add the group by directly invoking the save function in com_users component model.

$group = array('id'=>0, 'title'=>'Group Title', 'parent_id'=>1);
JLoader::import('joomla.application.component.model');
JLoader::import('group', JPATH_ADMINISTRATOR.'/components/com_users/models');
$groupModel = JModelLegacy::getInstance( 'Group', 'UsersModel' );

if(! $groupModel->save($group) )
{
   JFactory::getApplication()->enqueueMessage($groupModel->getError());
   return false;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.