src/Controller/VehiculeController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Vehicule;
  4. use App\Form\VehiculeType;
  5. use App\Repository\VehiculeRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/vehicule")
  12.  */
  13. class VehiculeController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/", name="app_vehicule_index", methods={"GET"})
  17.      */
  18.     public function index(VehiculeRepository $vehiculeRepository): Response
  19.     {
  20.         return $this->render('vehicule/index.html.twig', [
  21.             'vehicules' => $vehiculeRepository->findAll(),
  22.         ]);
  23.     }
  24.     /**
  25.      * @Route("/{idadr}/new", name="app_vehicule_new", methods={"GET", "POST"})
  26.      * @Route("/{id}/Admin/edit", name="app_vehicule_edit", methods={"GET", "POST"})
  27.      */
  28.     public function new(Request $requestVehicule $vehicule=nullVehiculeRepository $vehiculeRepository,$idadr=null, \App\Services\AppSevices $services): Response
  29.     {
  30.         if(!$vehicule){
  31.         $vehicule = new Vehicule();
  32.         }
  33.         if(!$vehicule->getAdherent()){
  34.                  $adr $services->getAdherents(['id' => $idadr])->getQuery()->getOneOrNullResult();
  35.                  $vehicule->setAdherent($adr);
  36.             
  37.         }
  38.         $form $this->createForm(VehiculeType::class, $vehicule);
  39.         $form->handleRequest($request);
  40.         if ($form->isSubmitted() && $form->isValid()) {
  41.             $vehiculeRepository->add($vehiculetrue);
  42.             $id=$vehicule->getAdherent()->getId();
  43.             return $this->redirectToRoute('app_adherent_show', ['id'=>$id], Response::HTTP_SEE_OTHER);
  44.         }
  45.         return $this->renderForm('vehicule/new.html.twig', [
  46.             'vehicule' => $vehicule,
  47.             'form' => $form,
  48.         ]);
  49.     }
  50.   
  51. }