简体   繁体   中英

Update specific user FOSuserbundle

i am working on a site web with symfony and in the part of dashboard admin i like that the admin can change the users profile so that for example change username or password

i am using FOSuserbundleand also table "fos_user" so how i can change users information ?

You should work with the fos_user.user_manager service.

In your controller, retrieve the user from the datastore with

$userManager = $this->get('fos_user.user_manager');
$user = $userManager->findUserBy(array('id'=> $id)); // get user by id
// or
$user = $userManager->findUserByUsername($username); // get user by username

then you can change what you want, example:

$user->setEmail('new_email@foo.com');
$user->setPlainPassword('new_password');

Finally, you can update the data with

$userManager->updateUser($user);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM