tetranz
tetranz

Reputation: 1962

FOSUserBundle, symfony 2.1. How can I add a role to a user at registration?

I'm sure this is a simple question but I can't quite see or find the correct way to do it.

How do I add a role to a user when that user is created using the registration form?

Upvotes: 1

Views: 5087

Answers (1)

tetranz
tetranz

Reputation: 1962

Found it. I was on the right track :)

Override the registration form handler.

https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md

Add

$user->addRole('ROLE_MYROLE');

before

parent::onSuccess()

Upvotes: 4

Related Questions