AppBundle\Entity\User::setRoles PHP Method

setRoles() public method

public setRoles ( array $roles )
$roles array
    public function setRoles(array $roles)
    {
        $this->roles = $roles;
    }

Usage Example

示例#1
0
 /**
  * @Route("/admin-login", name="admin-login")
  * @Template()
  */
 public function loginAction()
 {
     // создание пользователя
     $manager = $this->getDoctrine()->getManager();
     $user = new User();
     $user->setUsername('admin');
     $user->setSalt(md5(time()));
     $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
     $password = $encoder->encodePassword('admin', $user->getSalt());
     $user->setPassword($password);
     $user->setRoles('ROLE_OPERATOR');
     $user->setLastName('admin');
     $user->setFirstName('admin');
     $user->setSurName('admin');
     $user->setPhone('+79161111111');
     //
     $manager->persist($user);
     $manager->flush($user);
     if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
         $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
     } else {
         $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
     }
     $pages = $this->getDoctrine()->getRepository('AppBundle:Page')->findAll();
     return array('error' => $error, 'pages' => $pages);
 }
All Usage Examples Of AppBundle\Entity\User::setRoles