src/Controller/PageController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\ContactType;
  4. use App\Services\MailerService;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. class PageController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/", name="home")
  13.      */
  14.     public function index(MailerService $mailerRequest $request): Response
  15.     {
  16.         
  17.         //return $this->redirectToRoute('app_login');
  18.         if($this->getUser()){
  19.             $userRole = ($this->getUser()->getRoles()[0]);
  20.             $role strtolower(str_replace("ROLE_"""$userRole));
  21.             return $this->redirectToRoute("dashboard");
  22.         }
  23.         else {
  24.             $form $this->createForm(ContactType::class);
  25.             $form->handleRequest($request);
  26.         
  27.             /* Envoi d'un message de contact */
  28.             if ($form->isSubmitted() && $form->isValid()) {
  29.                 $to = ['contact@lotica.fr'];
  30.                 $data $form->getData();
  31.                 $params = [
  32.                     'data' => $data,
  33.                 ];
  34.                 $mailer->send("Nouveau message"$to"contactform_email"$params);
  35.                 $this->addFlash'success''Message envoyé. Nous vous répondrons le plus vite possible');
  36.                 return $this->redirectToRoute('home',['_fragment' => 'contact']);
  37.             }
  38.             return $this->render('page/index.html.twig', [
  39.                 'current' => 'home',
  40.                 'form' => $form->createView(),
  41.             ]);
  42.         }
  43.         
  44.     }
  45.     /**
  46.      * @Route("/a-propos", name="about")
  47.      */
  48.     public function about(): Response
  49.     {
  50.         $user $this->getUser() ? $this->getUser() : null;
  51.         return $this->render('page/about.html.twig', [
  52.             'current' => 'about',
  53.         ]);
  54.         
  55.     }
  56.     /**
  57.      * @Route("/services", name="services")
  58.      */
  59.     public function services(): Response
  60.     {
  61.         $user $this->getUser() ? $this->getUser() : null;
  62.         return $this->render('page/services.html.twig', [
  63.             'current' => 'services',
  64.         ]);
  65.         
  66.     }
  67.     /**
  68.      * @Route("/avantages", name="avantages")
  69.      */
  70.     public function avantages(): Response
  71.     {
  72.         $user $this->getUser() ? $this->getUser() : null;
  73.         return $this->render('page/avantages.html.twig', [
  74.             'current' => 'avantages',
  75.         ]);
  76.         
  77.     }
  78.     /**
  79.      * @Route("/temoignages", name="testimonials")
  80.      */
  81.     public function testimonials(): Response
  82.     {
  83.         $user $this->getUser() ? $this->getUser() : null;
  84.         return $this->render('page/testimonials.html.twig', [
  85.             'current' => 'testimonials',
  86.         ]);
  87.         
  88.     }
  89.     /**
  90.      * @Route("/contact", name="contact")
  91.      */
  92.     public function contact(): Response
  93.     {
  94.         $user $this->getUser() ? $this->getUser() : null;
  95.         return $this->render('page/contact.html.twig', [
  96.             'current' => 'contact',
  97.         ]);
  98.         
  99.     }
  100.     /**
  101.      * @Route("/cgv", name="cgv")
  102.      */
  103.     public function cgv(): Response
  104.     {
  105.         $user $this->getUser() ? $this->getUser() : null;
  106.         return $this->render('page/cgv.html.twig', [
  107.             'current' => 'cgv',
  108.         ]);
  109.         
  110.     }
  111.     /**
  112.      * @Route("/cgu", name="cgu")
  113.      */
  114.     public function cgu(): Response
  115.     {
  116.         $user $this->getUser() ? $this->getUser() : null;
  117.         return $this->render('page/cgu.html.twig', [
  118.             'current' => 'cgu',
  119.         ]);
  120.         
  121.     }
  122. }