<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Form\ContactType;
use App\Repository\ContactRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ContactController extends AbstractController
{
/**
* @Route("/contact", name="contact")
*/
public function index(Request $request, EntityManagerInterface $entityManager): Response
{
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($contact);
$entityManager->flush();
$this->addFlash(
'msg','Merci de nous avoir contacter'
);
return $this->redirectToRoute('contact', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('contact/index.html.twig', [
'contact' => $contact,
'form' => $form,
]);
}
/**
* @Route("admin/contact", name="contact_index", methods={"GET"})
*/
public function contact(ContactRepository $contactRepository): Response
{
return $this->render('admin_contact/index.html.twig', [
'contacts' => $contactRepository->findAll(),
]);
}
}