src/Controller/EntrepriseController.php line 18
<?php
namespace App\Controller;
use App\Entity\Entreprise;
use App\Form\EntrepriseType;
use App\Repository\CodeNafRepository;
use App\Repository\EntrepriseRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/entreprise')]
class EntrepriseController extends AbstractController
{
#[Route('/', name: 'app_entreprise_index', methods: ['GET'])]
public function index(EntrepriseRepository $entrepriseRepository): Response
{
return $this->render('entreprise/index.html.twig', [
'entreprises' => $entrepriseRepository->findAll(),
]);
}
#[Route('/new', name: 'app_entreprise_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntrepriseRepository $entrepriseRepository): Response
{
$entreprise = new Entreprise();
$form = $this->createForm(EntrepriseType::class, $entreprise);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entrepriseRepository->save($entreprise, true);
return $this->redirectToRoute('app_entreprise_edit', ["id"=>$entreprise->getId()], Response::HTTP_SEE_OTHER);
}
return $this->render('entreprise/new.html.twig', [
'entreprise' => $entreprise,
'form' => $form->createView(),
]);
}
#[Route('/{id}', name: 'app_entreprise_show', methods: ['GET'])]
public function show(Entreprise $entreprise, CodeNafRepository $codeNafRepo): Response
{
$naf = $codeNafRepo->findOneBy(["code"=>$entreprise->getNaf()]);
return $this->render('entreprise/show.html.twig', [
'entreprise' => $entreprise,
'naf' => $naf,
]);
}
#[Route('/{id}/edit', name: 'app_entreprise_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Entreprise $entreprise, EntrepriseRepository $entrepriseRepository, CodeNafRepository $codeNafRepo): Response
{
$form = $this->createForm(EntrepriseType::class, $entreprise);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entrepriseRepository->save($entreprise, true);
return $this->redirectToRoute('app_entreprise_show', ["id"=>$entreprise->getId()], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('entreprise/edit.html.twig', [
'entreprise' => $entreprise,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_entreprise_delete', methods: ['POST'])]
public function delete(Request $request, Entreprise $entreprise, EntrepriseRepository $entrepriseRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$entreprise->getId(), $request->request->get('_token'))) {
$entrepriseRepository->remove($entreprise, true);
}
return $this->redirectToRoute('app_entreprise_index', [], Response::HTTP_SEE_OTHER);
}
}