Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AppBundle\Controller\AdminController.php
- /.../
- /**
- *
- * @Route("/admin/register-doctor", name="doctor-registration")
- */
- public function registerAction(Request $request)
- {
- /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
- $userManager = $this->get('fos_user.user_manager');
- $user = $userManager->createUser();
- $personal = new PersonPersonal();
- $info = new PersonMainInfo();
- $personal->setPersonMainInfo($info);
- $personal->setPersonal($user);
- $form = $this->createForm(PersonPersonalType::class, $personal,array(
- 'action' => $this->generateUrl('doctor-registration'),
- 'method' => 'POST'));
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- dump($form->getData());dump($form->getErrors());die;
- $form->getData();
- $user->setPlainPassword("Default");
- $userManager->updateUser($user);
- $em = $this->getDoctrine()->getEntityManager();
- $personal->setCreationDate(new \DateTime());
- $em->persist($info);
- $em->flush();
- $em->persist($personal);
- $em->flush();
- $request->getSession()->getFlashBag()->add(
- 'success',
- 'Personalo darbuotojas sėkmingai pridėtas'
- );
- return $this->redirectToRoute('admin');
- } else {
- $errors = $form->getErrors();
- if (!empty($errors)) {
- foreach ($errors as $error) {
- $request->getSession()->getFlashBag()->add(
- 'error',
- $error->getMessage()
- );
- }
- }
- }
- return $this->render('main/register-doctor.html.twig', array(
- 'form' => $form->createView(),
- ));
- /.../
- }
- //AppBundle\Entity\PersonMainInfo.php
- /.../
- /**
- * @var string
- * @Assert\NotBlank()
- * @ORM\Column(name="address", type="string", length=500, nullable=true)
- */
- private $address;
- /**
- * @var string
- * @Assert\Email(
- * message = "The email '{{ value }}' is not a valid email.",
- * checkMX = true
- * )
- * @ORM\Column(name="email", type="string", length=600, nullable=true)
- */
- private $email;
- /.../
- //AppBundle\Form\Type\PersonMainInfoType.php
- /.../
- class PersonMainInfoType extends AbstractType
- {
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- // Validations only in Entity class with annotations? or need to validate here to??
- $builder
- ->add('name')
- ->add('lastname')
- ->add('birth_date', DateType::class, array(
- 'placeholder' => array(
- 'year' => 'Year', 'month' => 'Month', 'day' => 'Day', 'format' => 'yyyy-MM-dd',
- )))
- ->add('address')
- ->add('city')
- ->add('phone')
- ->add('email')
- ->add('job')
- ->add('doctor');
- }
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults([
- 'data_class' => 'AppBundle\Entity\PersonMainInfo',
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement