Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Method "DELETE" seems not to be seen by Symfony #48658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
micter59 opened this issue Dec 15, 2022 · 5 comments
Closed

Method "DELETE" seems not to be seen by Symfony #48658

micter59 opened this issue Dec 15, 2022 · 5 comments
Labels

Comments

@micter59
Copy link

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.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

Additional Context

image

@micter59 micter59 added the Bug label Dec 15, 2022
@MatTheCat
Copy link
Contributor

Did you enable framework.http_method_override?

@micter59
Copy link
Author

Aïe... so simple. No I did not. Thanks for your quick help !

I've also updated the recipes, and this has certainly been modified then.
And I didn't looked enough about the changes made by the update.

@micter59
Copy link
Author

I forgot to ask : maybe the documentation could be added about this configuration. I wen't many times through the documentation there : https://symfony.com/doc/current/routing.html#matching-http-methods and it is not mentionned.
Anyway, thanks for your help again.

@MatTheCat
Copy link
Contributor

Indeed it feels like it would be better! Are you up for a PR on https://github.com/symfony/symfony-docs?

@micter59
Copy link
Author

I never done that. So here's a try : symfony/symfony-docs#17565

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Dec 16, 2022
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

Update routing.rst

Add a note about allowing the http_method_override in the framework.yml file
symfony/symfony#48658

Commits
-------

576df85 Update routing.rst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants