src/Controller/ContactController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Form\ContactType;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  11. class ContactController extends AbstractController
  12. {
  13.     public function __construct(EntityManagerInterface $managerFlashBagInterface $flash){
  14.         $this->manager $manager;
  15.         $this->flash $flash
  16.     }
  17.     // ************************************AFFICHAGE FORMULAIRE DE CONTACT
  18.     /**
  19.      * @Route("/contact", name="app_contact")
  20.      */
  21.     public function index(Request $request): Response
  22.     {
  23.         $contact = new Contact();
  24.         $form $this->createForm(ContactType::class, $contact);
  25.         $form->handleRequest($request);
  26.             if ($form->isSubmitted() && $form->isValid()) {
  27.                 $this->manager->persist($contact);  
  28.                 $this->manager->flush(); 
  29.                 $this->flash->add('success''votre message a bien été envoyé, merci'); 
  30.                 return $this->redirectToRoute('app_contact'); 
  31.             }
  32.         
  33.         return $this->render('contact/index.html.twig', [
  34.             'formulaire' => $form->createView(),
  35.         ]); 
  36.     }
  37.     
  38.     // ***********************************GESTION DE CONTACT
  39.      /**
  40.      * @Route("/admin/all/contact", name="admin_app_contact_all") 
  41.      */
  42.     public function allcontactAdmin(): Response 
  43.     {
  44.         
  45.         $allTable $this->manager->getRepository(Contact::class)->findAll();   
  46.         // dd($contact);
  47.         return $this->render('contact/gestioncontact.html.twig', [ 
  48.             'contact' => $allTable,  
  49.         ]);   
  50.     
  51.     } 
  52. }