diff --git a/src/Controller/FridgeController.php b/src/Controller/FridgeController.php index cc00a7f..76764fb 100644 --- a/src/Controller/FridgeController.php +++ b/src/Controller/FridgeController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Entity\Fridge; use App\Form\FridgeType; use App\Repository\FridgeRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; @@ -23,10 +24,18 @@ class FridgeController extends AbstractController } #[Route('/single/{fridge}', name: '_single')] - public function single(Fridge $fridge, Request $request) + public function single(Fridge $fridge, Request $request, EntityManagerInterface $em) { $form = $this->createForm(FridgeType::class, $fridge); + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $em->persist($fridge); + $em->flush(); + + return $this->redirectToRoute('fridge_list'); + } + return $this->render('fridge/single.html.twig', [ 'form' => $form->createView(), ]);