本文整理汇总了PHP中AppBundle\Entity\User::setRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setRole方法的具体用法?PHP User::setRole怎么用?PHP User::setRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\User
的用法示例。
在下文中一共展示了User::setRole方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAction
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function createAction()
{
$error = '';
$name = $this->getRequest()->request->get('_username');
$display_name = $this->getRequest()->request->get('_display_name');
$password = $this->getRequest()->request->get('_password');
// var_dump($password); die;
$roleId = 2;
$role = $this->getDoctrine()->getRepository('AppBundle:Role')->find($roleId);
//var_dump($role_id); die;
if ($this->_isUniqueUser($name)) {
$user = new User();
$user->setDisplayName($display_name);
$user->setName($name);
$user->setPassword($password);
$user->setRole($role);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($user);
$em->flush();
return $this->render('AppBundle:Security:login.html.twig', array('name' => $name, 'error' => ''));
} else {
$error = "Користувач з іменем " . $name . ' уже існує. Будь оригінальний';
}
return $this->render("AppBundle:Film:index.html.twig", array('name' => $name, 'error' => $error));
}
示例2: load
public function load(ObjectManager $manager)
{
$faker = \Faker\Factory::create();
$x = 0;
while ($x++ < 25) {
$team = $this->getReference("team-{$x}");
$i = 0;
while ($i++ < 14) {
$player = new User();
$player->setName($faker->firstName);
$player->setLastName($faker->lastName);
$player->setRole(User::ROLE_PLAYER);
$player->setDescription($faker->text);
$player->setTeam($team);
$manager->persist($player);
$manager->flush();
}
$i = 0;
while ($i++ < 4) {
$coach = new User();
$coach->setName($faker->firstName);
$coach->setLastName($faker->lastName);
$coach->setRole(User::ROLE_COACH);
$coach->setDescription($faker->text);
$coach->setTeam($team);
$manager->persist($coach);
$manager->flush();
}
}
}
示例3: sodaDetail
/**
* @Route("/Seeddata", name="seed_data")
*/
public function sodaDetail()
{
//Users
$encoder = $this->container->get('security.password_encoder');
$em = $this->getDoctrine()->getManager();
$user1 = new User();
$user1->setName("Adam");
$user1->setUsername("adam42");
$user1->setRole("ROLE_ADMIN");
$user1->setPassword($encoder->encodePassword($user1, "1234"));
$user2 = new User();
$user2->setName("Peter");
$user2->setUsername("peterhans");
$user2->setRole("ROLE_USER");
$user2->setPassword($encoder->encodePassword($user2, "1234"));
$em->persist($user1);
$em->persist($user2);
$em->flush();
//Sodas
$em = $this->getDoctrine()->getManager();
$storage1 = new Storage();
$storage2 = new Storage();
$storage3 = new Storage();
$storage1->setQuantity(17);
$storage2->setQuantity(27);
$storage3->setQuantity(37);
$soda1 = new Soda();
$soda1->setName("Cola");
$soda1->setPrice(13);
$soda1->setDescription("Lækker original cola");
$soda1->setImageurl("images/cola.jpg");
$soda1->setStorage($storage1);
$soda2 = new Soda();
$soda2->setName("Sprite");
$soda2->setPrice(23);
$soda2->setDescription("Sprite direkte fra de friske kilder");
$soda2->setImageurl("images/sprite.jpg");
$soda2->setStorage($storage2);
$soda3 = new Soda();
$soda3->setName("Fanta");
$soda3->setPrice(33);
$soda3->setDescription("Fanta som man husker den");
$soda3->setImageurl("images/fanta.jpg");
$soda3->setStorage($storage3);
$em->persist($soda1);
$em->persist($soda2);
$em->persist($soda3);
$em->flush();
return $this->redirectToRoute('soda_overview');
}
示例4: registerPostAction
public function registerPostAction(Request $request)
{
$response = new Response();
$data = json_decode($request->getContent(), true);
if ($data['username'] === null || $data['password'] === null) {
return $response->setContent(json_encode(['errorMessage' => 'You must pass username and password']));
} else {
/** @var EncoderFactory $factory */
$factory = $this->get('security.encoder_factory');
$em = $this->getDoctrine()->getManager();
$user = new User();
$user->setRole(new Role());
$user->setIsActive(false);
$user->setUsername($data['username']);
$user->setPassword($data['password']);
/** @var Validator $validator */
$validator = $this->get('validator');
/** @var ConstraintViolationList $errors */
$errors = $validator->validate($user);
if (count($errors) > 0) {
$errorMessage = '';
foreach ($errors as $error) {
$errorMessage .= $error->getMessage();
}
return $response->setContent(json_encode(['errorMessage' => $errorMessage]));
} else {
/** @var PasswordEncoderInterface $encoder */
$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword($data['password'], $user->getSalt());
$user->setPassword($password);
$em->persist($user);
$em->flush();
return $response->setContent(json_encode(['message' => 'User successfully has registered.']));
}
}
}
示例5: load
public function load(ObjectManager $manager)
{
$role = new Role();
$userAdmin = new User();
$userAdmin->setUsername('admin');
$userAdmin->setPassword('password');
$userAdmin->setEmail('admin@admin.com');
$userAdmin->setRole($role->getId('ADMIN'));
$territory1 = new Territory();
$territory1->setName("Округ1");
$territory1->setKey("Описание");
$territory2 = new Territory();
$territory2->setName("Округ2");
$territory2->setKey("Описание");
$manager->persist($territory1);
$manager->persist($territory2);
$manager->persist($userAdmin);
$userUser = new User();
$userUser->setUsername('user');
$userUser->setPassword('password');
$userUser->setEmail('user@user.com');
$userUser->setRole($role->getId('USER'));
$manager->persist($userUser);
$manager->flush();
$userManager1 = new Manager();
$userManager1->setUsername('manager1');
$userManager1->setPassword('password');
$userManager1->setEmail('manager1@manager1.com');
$userManager1->setRole($role->getId('MANAGER'));
$userManager1->setSurname('manager1');
$userManager1->setName('manager1');
$userManager1->setPatronymic('manager1');
$userManager1->setGender('m');
$userManager1->setBirthday(new \DateTime('1980-01-01'));
$userManager2 = new Manager();
$userManager2->setUsername('manager2');
$userManager2->setPassword('password');
$userManager2->setEmail('manager2@manager2.com');
$userManager2->setRole($role->getId('MANAGER'));
$userManager2->setSurname('manager2');
$userManager2->setName('manager2');
$userManager2->setPatronymic('manager2');
$userManager2->setGender('m');
$userManager2->setBirthday(new \DateTime('1980-01-01'));
$manager->persist($userManager1);
$manager->persist($userManager2);
$userPresenter1 = new Presenter();
$userPresenter1->setUsername('presenter1');
$userPresenter1->setPassword('password1');
$userPresenter1->setEmail('presenter1@presenter1.com');
$userPresenter1->setRole($role->getId('PRESENTER'));
$userPresenter1->setSurname('Иванов');
$userPresenter1->setName('Иван');
$userPresenter1->setPatronymic('Иванович');
$userPresenter1->setGender('m');
$userPresenter1->setBirthday(new \DateTime('1980-01-01'));
$userPresenter1->setTerritory($territory1);
$userPresenter1->setManager($userManager1);
$userPresenter2 = new Presenter();
$userPresenter2->setUsername('presenter2');
$userPresenter2->setPassword('password2');
$userPresenter2->setEmail('presenter2@presenter2.com');
$userPresenter2->setRole($role->getId('PRESENTER'));
$userPresenter2->setSurname('Петров');
$userPresenter2->setName('Петр');
$userPresenter2->setPatronymic('Петрович');
$userPresenter2->setGender('m');
$userPresenter2->setBirthday(new \DateTime('1980-01-01'));
$userPresenter2->setManager($userManager2);
$userPresenter2->setTerritory($territory2);
$manager->persist($userPresenter1);
$manager->persist($userPresenter2);
$manager->flush();
}