src/Controller/FrontOffice/HomeController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontOffice;
  3. use App\Entity\Message;
  4. use App\Entity\Contact;
  5. use App\Form\BackOffice\MessageType;
  6. use App\Form\BackOffice\ContactType;
  7. use App\Repository\EmployesRepository;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Mime\Email;
  13. use Symfony\Component\Mailer\MailerInterface;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. class HomeController extends AbstractController
  17. {
  18.     /**
  19.      * @Route("/", name="home")
  20.      */
  21.     public function index(EmployesRepository $employesRepositoryRequest $requestEntityManagerInterface $manager)
  22.     {
  23.         $message = new Message();
  24.         $form $this->createForm(MessageType::class, $message);
  25.         $form->handleRequest($request);
  26.         
  27.         if($form->isSubmitted() && $form->isValid())
  28.         {
  29.             $message->setDate(new \DateTime());
  30.             $manager->persist($message);
  31.             $manager->flush();
  32.             
  33.             $this->addFlash(
  34.                 'success',
  35.                 "Votre message a été bien envoyer, Merci..."
  36.             );
  37.             return $this->redirectToRoute('home');
  38.         }
  39.         return $this->render('FrontOffice/home.html.twig', [
  40.             'leaderships' => $employesRepository->findBy(
  41.                 [],
  42.                 ['id' => 'DESC'],
  43.                 8
  44.             ),
  45.             'formMessage' => $form->createView()
  46.         ]);
  47.     }
  48.      /**
  49.      * @Route("/contact", name="contact")
  50.      */
  51.     public function contact( \Swift_Mailer $mailerRequest $requestEntityManagerInterface $manager)
  52.     {
  53.         $contact = new Contact();
  54.         $form $this->createForm(ContactType::class, $contact);
  55.         $form->handleRequest($request);
  56.         if($form->isSubmitted() && $form->isValid() )
  57.         {
  58.             dd($contact);    
  59.             // $manager->persist($contact);
  60.             // $manager->flush();    
  61.             // 
  62.             
  63.             //SwiftMailer
  64.             $message = (new \Swift_Message('Demande de rendez-vous'))
  65.                     ->setFrom('ot.freddino@gmail.com')
  66.                     ->setTo($contact->getEmail());      
  67.             $message->setBody(
  68.                 $this->renderView(
  69.                     // templates/emails/registration.html.twig
  70.                     'mail/mail.html.twig',
  71.                     [
  72.                         'sujet' => $contact->getSubject(),
  73.                         'message' => $contact->getMessage()
  74.                     ]
  75.                 )
  76.             );
  77.             $message->setContentType("text/html");
  78.             $_result $mailer->send($message);
  79.             $_headers $message->getHeaders();
  80.             $_headers->addTextHeader('MIME-Version''1.0');
  81.             $_headers->addTextHeader('X-Mailer''PHP v' phpversion());
  82.             $_headers->addParameterizedHeader('Content-type''text/html', ['charset' => 'utf-8']);
  83.         }
  84.         return $this->render('FrontOffice/contact.html.twig',[
  85.             'form' => $form->createView()
  86.         ]);
  87.     }
  88. }