i'm learning to use Symfony right now, and i'm having an issue with the routing system. I'm currently trying to edit a "Pin" using a form. So here is what I have in my controller so far for the update of a "Pin".
/**
* @Route("/pins/{id<[0-9]+>}/edit", name="app_pins_edit", methods="GET|PUT")
*/
public function edit(Request $request, Pin $pin, EntityManagerInterface $em): Response
{
$form = $this->createForm(PinType::class,$pin,[
'method'=>'PUT'
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->flush();
$this->addFlash('success','Pin successfully updated');
return $this->redirectToRoute('app_home');
}
return $this->render('pins/edit.html.twig', [
'pin' => $pin,
'form' => $form->createView(),
]);
}
And the error I have is this one when I try to update a Pin : "No route found for "POST"Method Not Allowed (Allow: GET, PUT)".
I'm assuming it's because I wrote "methods="GET|PUT"" in my route. And this is what I actually need. But I keep having this error.
PS : With the createForm I have a hidden input in the form like this :
<input type="hidden" name="_method" value="PUT"
That is supposed to be read by symfony as "I want the put method" but doesn't seem to work.
Thank you for reading this ! And thank you for helping if you do!
PS : If you need more information or more code i'll be happy to share it with you.