Hi,
i've a Customer Entity with an assiciated User Entity. The User class
extends FOS\UserBundle\Entity\User
On Signup i've to do some more things than just create a new User. I
want to create a Customer with one User (can have many) and some
further things (e. g. create Random Password, send Mail for "double
opt in" and so on).
My question is: How can i create a User manually?
$userManager = $this->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setEmail('
te...@blub.com');
$user->setPlainPassword('12345'); // should be random password
$customer = new Customer();
// .... set some customer properties
$customer->addUsers($user);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($customer);
$em->flush();
But there are some errors by doing this, e.g.:
Integrity constraint violation: 1048 Column 'salt' cannot be null
The i've tried the code below instead of user_manager-Service
"createUser()"-method:
$userManipulator = $this->get('fos_user.util.user_manipulator');
$user = $userManipulator->create(
'Test',
'testpassword',
'
te...@mail.com',
false,
false
);
The error message is:
Warning: array_search() expects parameter 2 to be array, null given
in /the/full/path/vendor/bundles/FOS/UserBundle/Model/User.php line
507
It would be nice to have some documentation how to create users
programatically in own code/controller.
Can someone help me?
Tnx
Jehu