src/Controller/Frontend/ContactController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\String\Slugger\AsciiSlugger;
  10. use Nelmio\ApiDocBundle\Annotation\Security;
  11. use App\Service\ContactService;
  12. use App\Service\AgencyService;
  13. use App\Repository\ContactRepository;
  14. use App\Entity\Contact;
  15. use App\Form\ContactType;
  16. /**
  17.  * Frontend: Contact controller.
  18.  * @Route("/contact", name="frontend_contact")
  19. */
  20. class ContactController extends AbstractController
  21. {
  22.     /**
  23.      * @var ContactService
  24.      */
  25.     private $ContactService;
  26.     public function __construct(ContactService $contactService)
  27.     {
  28.         $this->ContactService $contactService;
  29.     }
  30.     // /**
  31.     //  * @Route("", name="_liste")
  32.     //  */
  33.     // public function getContacts(ContactRepository $ContactRepository)
  34.     // {
  35.     //     $liste = $this->ContactService->getContact();
  36.     //     return $this->render('contact/list.html.twig', ['liste' => $liste]);
  37.     // }
  38.     /**
  39.      * @Route("/add", name="_add")
  40.      */
  41.     public function addAction(Request $requestAgencyService $AgencyService)
  42.     {
  43.         $agencies $AgencyService->getAgency();
  44.         $Contact = new Contact();
  45.         $form $this->createForm(ContactType::class, $Contact);
  46.         $form->handleRequest($request);
  47.         if ($form->isSubmitted() && $form->isValid()) {
  48.             $Contact $this->ContactService->persist($Contact);
  49.             $request->getSession()->getFlashBag()->add('success''ajout avec succĂ©e !');
  50.             return $this->redirectToRoute('frontend_index');
  51.         }
  52.         return $this->render('contact.html.twig', array('form' => $form->createView(), 'agencies' => $agencies'ligne' => $Contact));
  53.     }
  54. }