It looks pretty simple and I'm a begginer with Symfony, but couldn't figure it out.
I'm using FOSUserBundle, and I'm trying to add a specific role (ROLE_ADMIN) to a specific user (e.g. me), so when the user logs in that role is assigned and he can access certain pages.
I tried putting something like this in the __construct() method of my User entity, but it didn't work:
if($this->getUsername()=='johndoe') $this->addRole('ROLE_ADMIN');
When I log in as that user, the debugging utilities show only the 'ROLE_USER', os it is not working.
Is that a right code? Where should I put it?
Update:
There was a silly error that accidentally found. I had created the User entity before isntalling FOSUserBundle, and somehow the user I was trying to promote gave me errors through CLI. Maybe it wasn't properly stored in the database. Once I created a new one and tried again, the command worked as expected.