src/Controller/IndexController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\ContactType;
  4. use App\Form\TestimonialType;
  5. use App\Repository\ExperiencesRepository;
  6. use App\Repository\InformationsRepository;
  7. use App\Repository\ServicesRepository;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Mailer\MailerInterface;
  12. use Symfony\Component\Mime\Email;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class IndexController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/", name="app_index")
  18.      */
  19.     public function index(Request $requestMailerInterface $mailerInformationsRepository $informationsRepositoryServicesRepository $servicesRepositoryExperiencesRepository $experiencesRepository): Response
  20.     {
  21.         $information $informationsRepository->findAll()[0];
  22.         $services $servicesRepository->findAll();
  23.         $experiences $experiencesRepository->findBy(['enabled' => true]);
  24.         $form $this->createForm(ContactType::class);
  25.         // create testimonials form
  26.         $testimonialsForm $this->createForm(TestimonialType::class);
  27.         $testimonialsForm->handleRequest($request);
  28.         $form->handleRequest($request);
  29.         if ($form->isSubmitted() && $form->isValid()) {
  30.             $contactFormData $form->getData();
  31.             $message = (new Email())
  32.                 ->from($_ENV['MAIL_FROM'])
  33.                 ->replyTo($contactFormData['email'])
  34.                 ->to($_ENV['MAIL_TO'])
  35.                 ->subject(ucfirst(mb_strtolower($contactFormData['subject'])))
  36.                 ->text('Sender : '.$contactFormData['email'].\PHP_EOL.
  37.                     $contactFormData['message'],
  38.                     'text/plain');
  39.             $mailer->send($message);
  40.             $this->addFlash('success''Votre message a été envoyé');
  41. //            return $this->redirect($request->getUri());
  42.         }
  43.         return $this->render('index/about.html.twig', [
  44.             'form' => $form->createView(),
  45.             'testimonialsForm' => $testimonialsForm->createView(),
  46.             'information' => $information,
  47.             'services' => $services,
  48.             'experiences' => $experiences,
  49.         ]);
  50.     }
  51. }