Reputation: 503
This is the action from a UserController.php controller:
public function createAction()
{
$userManager = $this->container->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setUsername('test');
$user->setEmail('[email protected]');
$user->setPassword('test');
$user->setEnabled(1);
$user->setRoles(array('ROLE_ADMIN'));
return $this->redirect($this->generateUrl('crm_user_index'));
}
I followed the documentation but it doesn't work at all.
What's wrong ? Is this the best way to create a user from an action in a controller ?
Upvotes: 0
Views: 130
Reputation: 5877
Yoy have to flush the doctrine unit of work, like:
$this->getDoctrine()->getEntityManager()->flush();
or:
$userManager->updateUser($user);
Upvotes: 1