Question

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('test@test.com');
    $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 ?

Was it helpful?

Solution

Yoy have to flush the doctrine unit of work, like:

$this->getDoctrine()->getEntityManager()->flush();

or:

$userManager->updateUser($user);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top