我有一个问题" @ParamConverter注释找不到对象"在我尝试删除表的选定项目时,在Symfony 3.4上。我认为这是一个问题,当我试图获得#34;奇观"使用id(" findOneBy()")
这是我的代码(html.twig):
<form method="delete" action="{{ path('admin_spectacle_delete_selected') }}">
<button class="content-red btn btn-fabop" type="submit"><i class="fa fa-trash"></i> Tout supprimer</button>
<div class="table-responsive">
<table id="myTable" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th style="text-align:center;"><input type="checkbox" id="all"></th>
<th>Nom</th>
<th>Lieu</th>
<th>Date spectacle</th>
<th>Annee</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for spectacle in spectacles %}
<tr>
<td id="spectacle{{ spectacle.id }}"><input type="checkbox" name='multiSelected[]' value="{{ spectacle.id }}"></td>
<td>{{ spectacle.nom }}</td>
<td>{{ spectacle.lieu }}</td>
<td>{{ spectacle.dateSpectacle }}</td>
<td>{{ spectacle.annee }}</td>
<td>
<a class="content-blue btn-fabop btn" href="{{ path('admin_spectacle_show', { 'id': spectacle.id }) }}"><i class="fa fa-search"></i> Détail</a>
<a class="content-purple btn-fabop btn" href="{{ path('admin_spectacle_edit', { 'id': spectacle.id }) }}"><i class="fa fa-pencil"></i> Edition</a>
<a class="content-red btn-fabop btn" href="{{ path('admin_spectacle_delete_confirmed', { 'id': spectacle.id }) }}"><i class="fa fa-trash"></i> Suppression</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
和控制器:
/**
* Confirmation delete
*
* @Route("/deleteSelected", name="admin_spectacle_delete_selected")
*/
public function deleteSelectedAction(Request $request)
{
$items_selected_id = $request->get('multiSelected');
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository(Spectacle::class);
foreach($items_selected_id as $item_id) {
$spectacle = $repository->findOneById($item_id);
if (!$spectacle) {
throw $this->createNotFoundException(
'No spectacle found for id '.$spectacle
);
}
else{
$em->remove($spectacle);
}
}
$em->flush();
return $this->redirectToRoute('admin_spectacle_index');
}
感谢您的回复!!
答案 0 :(得分:1)
请尝试更改此内容:
<form method="delete"
到此:
<form method="post"
因为看起来你的变量就像POST
动作而不是DELETE