本文整理匯總了PHP中AppBundle\Entity\User::setIsAdmin方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::setIsAdmin方法的具體用法?PHP User::setIsAdmin怎麽用?PHP User::setIsAdmin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AppBundle\Entity\User
的用法示例。
在下文中一共展示了User::setIsAdmin方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: registerAction
/**
* @Route("/register", name="registration")
*/
public function registerAction(Request $request)
{
// 1) build the form
$user = new User();
$user->setIsActive(false);
$user->setIsAdmin(false);
$form = $this->createForm(new UserType(), $user);
// 2) handle the submit (will only happen on POST)
$form->handleRequest($request);
if (!$form->isValid()) {
echo $form->getErrorsAsString();
}
if ($form->isValid() && $form->isSubmitted()) {
$user->setPassword($user->getPlainPassword());
$user->setIsActive(false);
// 4) save the User!
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
// ... do any other work - like send them an email, etc
// maybe set a "flash" success message for the user
return new Response("<html>USUARIO REGISTRADO CORRECTAMENTE</html>");
}
return $this->render('registration/register.html.twig', array('form' => $form->createView()));
}
示例2: registerAction
/**
* @Route("/register", name="user_registration")
*/
public function registerAction(Request $request)
{
// 1) build the form
$user = new User();
$user->setIsActive(true);
$user->setIsAdmin(false);
$form = $this->createForm(UserType::class, $user);
// 2) handle the submit (will only happen on POST)
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// 3) Encode the password (you could also do this via Doctrine listener)
$password = $this->get('security.password_encoder')->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
// 4) save the User!
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
// ... do any other work - like send them an email, etc
// maybe set a "flash" success message for the user
return $this->redirectToRoute('homepage');
}
return $this->render('security/register.html.twig', array('form' => $form->createView()));
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$users = $em->getRepository('AppBundle:User')->findAll();
if ($users) {
foreach ($users as $user) {
if ($user->getIsAdmin()) {
throw new \RuntimeException('Admin already exists!');
}
}
}
$name = $input->getArgument('name');
$email = $input->getArgument('email');
$plainPassword = $input->getArgument('password');
$userExists = $em->getRepository('AppBundle:User')->findOneBy(array('username' => $name));
$userWithEmailExists = $em->getRepository('AppBundle:User')->findOneBy(array('email' => $email));
if ($userExists) {
throw new \RuntimeException('User already exists: ' . $name);
}
if ($userWithEmailExists) {
throw new \RuntimeException('User with this email already exists: ' . $email);
}
$admin = new User();
$admin->setIsAdmin(true);
$admin->setUsername($name);
$admin->setEmail($email);
$admin->setPlainPassword($plainPassword);
$password = $this->getContainer()->get('security.password_encoder')->encodePassword($admin, $admin->getPlainPassword());
$admin->setPassword($password);
$em->persist($admin);
$em->flush();
$output->writeln('Admin created!');
}