<?php
namespace App\Controller\Frontend;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\String\Slugger\AsciiSlugger;
use Nelmio\ApiDocBundle\Annotation\Security;
use App\Service\ContactService;
use App\Service\AgencyService;
use App\Repository\ContactRepository;
use App\Entity\Contact;
use App\Form\ContactType;
/**
* Frontend: Contact controller.
* @Route("/contact", name="frontend_contact")
*/
class ContactController extends AbstractController
{
/**
* @var ContactService
*/
private $ContactService;
public function __construct(ContactService $contactService)
{
$this->ContactService = $contactService;
}
// /**
// * @Route("", name="_liste")
// */
// public function getContacts(ContactRepository $ContactRepository)
// {
// $liste = $this->ContactService->getContact();
// return $this->render('contact/list.html.twig', ['liste' => $liste]);
// }
/**
* @Route("/add", name="_add")
*/
public function addAction(Request $request, AgencyService $AgencyService)
{
$agencies = $AgencyService->getAgency();
$Contact = new Contact();
$form = $this->createForm(ContactType::class, $Contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$Contact = $this->ContactService->persist($Contact);
$request->getSession()->getFlashBag()->add('success', 'ajout avec succée !');
return $this->redirectToRoute('frontend_index');
}
return $this->render('contact.html.twig', array('form' => $form->createView(), 'agencies' => $agencies, 'ligne' => $Contact));
}
}