So I'm guessing this is just a basic error but I can't for the life of me figure it out.
I'm trying to create a new user, set some attributes and add them to a group I've already made. The following code all works but for the line:
craft()->userGroups->assignUserToGroups($newUser->getContent()->id, 11);
public function actionSendSignup()
{
$this->requirePostRequest();
$user = new UserModel();
$user->username = craft()->request->getPost('memberEmail');
$user->unverifiedEmail = craft()->request->getPost('memberEmail');
$data = [
"firstName" => craft()->request->getPost('memberFirstName'),
"lastName" => craft()->request->getPost('memberLastName'),
"email" => craft()->request->getPost('memberEmail'),
];
$user->setAttributes($data);
$user->pending = true;
$success = craft()->users->saveUser($user);
if ($success) {
craft()->search->indexElementAttributes($user);
// Assign them to my user group 11
craft()->userGroups->assignUserToGroups($newUser->getContent()->id, 11);
// Update the Element Index
craft()->search->indexElementAttributes($user);
}
return $this->returnJson($user->getContent());
}
The get id returns a number that appears right (it's a low integer), but I get a SQL error on adding the row to the join table users_usergroups and the userId doesn't match the user that was created in the system.
I'm guessing I'm misunderstanding the user id field?