<?php
namespace App\Controller;
use App\Entity\Rejoindre;
use App\Form\RejoindreType;
use App\Repository\RejoindreRepository;
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 RejoindreController extends AbstractController
{
/**
* @Route("/rejoindre", name="rejoindre")
*/
public function index(Request $request, EntityManagerInterface $entityManager): Response
{
$rejoindre = new Rejoindre();
$form = $this->createForm(RejoindreType::class, $rejoindre);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$fichier = $rejoindre->getFichier();
$filename = uniqid().'.'.$fichier->guessExtension();
$fichier->move(
$this->getParameter('images_directory'),
$filename
);
$rejoindre->setFichier($filename);
$entityManager->persist($rejoindre);
$entityManager->flush();
$this->addFlash(
'msg','Merci de nous rejoindre'
);
return $this->redirectToRoute('rejoindre', [], Response::HTTP_SEE_OTHER);
}
return $this->render('rejoindre/index.html.twig', [
'form' => $form->createView()
]);
}
/**
* @Route("admin/rejoindre", name="rejoindre_index", methods={"GET"})
*/
public function rejoindre(RejoindreRepository $rejoindreRepository): Response
{
return $this->render('admin_rejoindre/index.html.twig', [
'rejoindres' => $rejoindreRepository->findAll(),
]);
}
}