src/Controller/ContactController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Form\ContactType;
  5. use App\Notification\ContactNotification;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use App\Repository\ImagebackgroundRepository;
  11. class ContactController extends AbstractController
  12. {
  13.     /**
  14.      * @var ImagebackgroundRepository
  15.      */
  16.     private $i_repository;
  17.     public function __construct(ImagebackgroundRepository $i_repository)
  18.     {
  19.         $this->i_repository $i_repository;
  20.     }
  21.     /**
  22.      * @Route("/contact", name="contact")
  23.      * @return Response
  24.      */
  25.     public function contact(Request $requestContactNotification $notification): Response
  26.     {
  27.         $image $this->i_repository->find(1);
  28.         $contact = new Contact();
  29.         $form $this->createForm(ContactType::class, $contact);
  30.         $form->handleRequest($request);
  31.         if ($form->isSubmitted() && $form->isValid()) {
  32.             $notification->notify($contact);
  33.             $this->addFlash('success''votre email a bien été envoyé ');
  34.             return $this->redirectToRoute('contact');
  35.         }
  36.         return $this->render('pages/contact.html.twig', [
  37.             'current_menu' => 'contact',
  38.             'form' => $form->createView(),
  39.             'img' => $image
  40.         ]);
  41.     }
  42. }