Skip to content

Commit 827e153

Browse files
committed
feature #825 [make:crud] use POST method instead of DELETE (jrushlow)
This PR was merged into the 1.0-dev branch. Discussion ---------- [make:crud] use POST method instead of DELETE Starting in Symfony 5.3, `framework.http_method_override` defaults to `false`. This prevents CRUD form submission for `PUT`, `PATCH` &/or `DELETE` methods. See symfony/recipes#892 ~This PR conditionally sets `http_method_override` to true when using `make:crud` if using Symfony 5.3+~ We stop using the `DELETE` method override in favor of using `POST` on the delete operation. Commits ------- fc9cd2a [make:crud] use post method for deletes
2 parents 24c7334 + fc9cd2a commit 827e153

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/Resources/skeleton/crud/controller/Controller.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public function edit(Request $request, <?= $entity_class_name ?> $<?= $entity_va
114114
}
115115

116116
<?php if ($use_attributes) { ?>
117-
#[Route('/{<?= $entity_identifier ?>}', name: '<?= $route_name ?>_delete', methods: ['DELETE'])]
117+
#[Route('/{<?= $entity_identifier ?>}', name: '<?= $route_name ?>_delete', methods: ['POST'])]
118118
<?php } else { ?>
119119
/**
120-
* @Route("/{<?= $entity_identifier ?>}", name="<?= $route_name ?>_delete", methods={"DELETE"})
120+
* @Route("/{<?= $entity_identifier ?>}", name="<?= $route_name ?>_delete", methods={"POST"})
121121
*/
122122
<?php } ?>
123123
public function delete(Request $request, <?= $entity_class_name ?> $<?= $entity_var_singular ?>): Response
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<form method="post" action="{{ path('<?= $route_name ?>_delete', {'<?= $entity_identifier ?>': <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
2-
<input type="hidden" name="_method" value="DELETE">
32
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ <?= $entity_twig_var_singular ?>.<?= $entity_identifier ?>) }}">
43
<button class="btn">Delete</button>
54
</form>

0 commit comments

Comments
 (0)