Generally, the user group id is 2 and the administrator group id is 8. Since setting the group id in User Class will also verify whether the current user has the permission to manage the role, so without logging in, you can only set 2 first and then use SQL to change it. 8.
JPluginHelper::importPlugin('user'); $user = new JUser; $data = array(- 'name' => 'Admin',
- 'username' => 'admin',
- 'email' => 'catcat811@hotmail.com',
- 'password' => '123456',
- 'groups' => array(2),
- 'block' => 0
- );
- $ user->bind($data);
- $user->save();
- $db = JFactory::getDbo();
- $db->setQuery('SELECT id FROM #__users WHERE username='. $db->Quote($data['username']));
- $user_id = $db->loadResult();
- if($user_id) {
- $db->setQuery('UPDATE #__user_usergroup_map SET group_id=8 WHERE user_id='.(int)$user_id);
- $db->query();
- }
-
-
- Copy code
|