Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsonasik/745c49d0dc0aae26a77c to your computer and use it in GitHub Desktop.
Save samsonasik/745c49d0dc0aae26a77c to your computer and use it in GitHub Desktop.
ZfcUser - BjyAuthorize : set role after register
// adopted from http://stackoverflow.com/questions/17596639/zfcuser-add-user-role-after-registration
/** set role after register
*
*/
public function onBootstrap(EventInterface $e)
{
$services = $e->getApplication()->getServiceManager();
$zfcServiceEvents = $services->get('zfcuser_user_service')->getEventManager();
$zfcServiceEvents->attach('register', function($e) use ($services) {
$user = $e->getParam('user');
$em = $services->get('Doctrine\ORM\EntityManager');
$defaultUserRole = $em->getRepository('AppEntity\Entity\Role')
->findOneBy(array('roleId' => 'user'));
$user->addRole($defaultUserRole);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment