Fridge: allow saving when editing a fridge
This commit is contained in:
parent
725fa47c6d
commit
39e028bdca
@ -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(),
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user