本文整理汇总了PHP中FOS\UserBundle\Model\UserInterface::addRole方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::addRole方法的具体用法?PHP UserInterface::addRole怎么用?PHP UserInterface::addRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\UserBundle\Model\UserInterface
的用法示例。
在下文中一共展示了UserInterface::addRole方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onSuccess
protected function onSuccess(UserInterface $user, $confirmation)
{
// Note: if you plan on modifying the user then do it before calling the
// parent method as the parent method will flush the changes
$user->addRole('ROLE_NORMAL_USER');
$user->setRegistrationStatus('complete');
$user->setSalt($this->random_key_generator(20));
parent::onSuccess($user, $confirmation);
// otherwise add your functionality here
}
示例2: updateRoles
/**
*
*/
public function updateRoles(UserInterface $user)
{
$roles = $user->getRoles();
$roleRepository = $this->objectManager->getRepository('WeavingTheWebUserBundle:Role');
foreach ($roles as $role) {
$roleName = (string) $role;
$roleEntity = $roleRepository->findOneByRole($roleName);
$user->removeRole($role);
$user->addRole($roleEntity);
}
}