src/Controller/Front/HomeController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Mailer\MailerInterface;
  8. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. use Symfony\Component\Mime\Address;
  11. use App\Repository\Blog\PostRepository;
  12. class HomeController extends AbstractController
  13. {
  14.     public function index(PostRepository $postRepository): Response
  15.     {
  16.         $recentPost $postRepository->findRecent(2);
  17.         return $this->render('front/home/index.html.twig'compact('recentPost'));
  18.     }
  19.     public function about(): Response
  20.     {
  21.         return $this->render('front/home/about.html.twig');
  22.     }
  23.     public function contact(): Response
  24.     {
  25.         return $this->render('front/contact/index.html.twig');
  26.     }
  27.     public function contactSend(Request $requestMailerInterface $mailerTranslatorInterface $translator): Response
  28.     {
  29.         $data $request->request->All();
  30.         if (!empty($data)) {
  31.             $senderMail $this->getParameter('sender_mail');
  32.             $email = (new TemplatedEmail())
  33.                 ->from(new Address($senderMail'Demande de contact'))
  34.                 ->to('contact@sofel-legal-consulting.com')
  35.                 ->subject($request->request->get('subject'))
  36.                 ->htmlTemplate('front/contact/email.html.twig')
  37.                 ->context($data);
  38.             $mailer->send($email);
  39.             $this->addFlash('success_en'$translator->trans('app.contact.sendsuccess'));
  40.         }
  41.         
  42.         return $this->redirectToRoute('contact');
  43.     }
  44.     /**
  45.      * @Route("/lang", name="switch_lang", methods={"GET"})
  46.      */
  47.     public function switch_lang(Request $request): Response
  48.     {
  49.         $request->setLocale($request->query->get('lang'));
  50.         return $this->redirectToRoute('index');
  51.     }
  52. }