Description
Symfony version(s) affected
6.2.1
Description
I bumped my application from PHP 7.4 to 8.1, and from Symfony 5.4 to 6.2.
Before that, using the "delete" method was ok. I mean, in my controller, I limit a route to "DELETE" method, and then in my HTML form, I add the "".
My code didn't change except I went from using annotations to PHP properties on the route. But the HTML form did not change.
But now Symfony give me the error :
No route found for "POST http://192.168
6142
.0.146:8090/intervenants/601": Method Not Allowed (Allow: GET, DELETE)
If i understand well, the route with the delete method is well seen. In the request, the field "_method" with value "delete" can be seen. So I don't understand why it doesn't work anymore. I've looked through the changelog of 6.0, 6.1 and 6.2, but didn't find anything about that.
How to reproduce
Here's the code in the controller :
#[Route(path: '/{id}', name: 'rdvs_delete', requirements: ['id' => '\d+'], methods: ['DELETE'])]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function delete(Rdvs $rdv, Request $request): Response
{
if ($this->rdvsManager->isRdvModifiable($rdv)) {
if ($this->isCsrfTokenValid('delete' . $rdv->getId(), $request->request->get('_token'))) {
$this->rdvsManager->deleteRdv($rdv);
$this->addFlash(
'success',
'Suppression effectuée'
);
} else {
$this->addFlash(
'error',
'Erreur - la suppression n\'a pas été effectuée'
);
}
}
// Renvoyer sur la page d'où vient l'utilisateur
$referer = $request->headers->get('referer');
return $this->redirect($referer);
}
And here's the HTML form :
<form class="mb-0" method="post" action="{{path('rdvs_delete', {'id': rdv.id}) }}"
onsubmit="return confirm('Etes-vous sûr de vouloir supprimer ce rendez-vous ?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ rdv.id) }}">
<input type="hidden" name="_method" value="delete">
<button class="btn btn-outline-danger border-0">
<i class="fas fa-trash" aria-hidden="true"></i>
</button>
</form>
Possible Solution
No response