1
刪除記錄
我在我的樹枝中有一個按鈕,我希望能夠從表中刪除記錄。當我點擊刪除按鈕頁面重新加載但沒有記錄被刪除。Symfony2從表
這裏是我的樹枝
<h1>Admin Area - The football blog</h1>
<table class="zebra">
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
{% for entity in adminentities %}
<td>{{entity.postTitle}}</td>
<td>{{ entity.postDescription }} </td>
<td> <a href="{{ path('deletepost', { 'id': entity.id }) }}">Delete</a> || Edit</td>
</tr>
{% endfor %}
</tbody>
</table>
這裏是我的控制器。
/**
* @Route("/posted/admin", name="deletepost")
* @Template()
*/
public function admindeleteAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$adminentities = $em->getRepository('BlogBundle:posted')
->findOneBy(array('post'=>$post->getId(), 'id'=>$id));
$em->remove($adminentities);
$em->persist($adminentities);
$em->flush();
return $this->render('BlogBundle:Default:admin.html.twig');
}
我應該在哪裏添加這個?在我調用flush方法之前,我已經堅持了它。沖水後? – g1bbles 2015-03-13 15:53:51
你不必堅持實體,只需刪除並刷新它。 – djoosi 2015-03-13 15:54:33
嗯我已經刪除了堅持行,但它仍然無法正常工作。有什麼建議麼? – g1bbles 2015-03-13 16:20:01