Delete data
Vederea data.html.twig
{% extends 'base.html.twig' %}
{% block body %}
<table>
<tr>
<th>Nume</th>
<th>Culoare</th>
<th>Marime</th>
<th>Pret</th>
<th colspan="3">Actions</th>
</tr>
{% for key in flowers %}
<tr>
<td>{{ key.nume }}</td>
<td>{{ key.culoare }}</td>
<td> {{ key.marime }}</td>
<td>{{ key.pret }}</td>
<td><a href="{{ app.request.baseUrl() }}/show/{{key.id}}">View</a>
<a href="{{ app.request.baseUrl() }}/edit/{{key.id}}">Edit</a>
<a href="{{ app.request.baseUrl() }}/delete/{{key.id}}" onclick="return confirm('Are you sure you want to delete this
item?');">Delete</a>
</td>
</tr>
{% endfor %}
</table>
<a href="{{ app.request.baseUrl() }}/data/add">Insert a record</a>
{% endblock %}
Controller-ul DataController
………………………………
/**
* @Route("/delete/{id}")
* @Method({"GET", "POST"})
*/
public function deleteAction($id){
$em=$this->getDoctrine()->getManager();
$flower = $this->getDoctrine()->
getRepository(Flower::class)->find($id);
$em->remove($flower);
$em->flush();
return $this->redirectToRoute('data');
}

17. delete data

  • 1.
  • 2.
    Vederea data.html.twig {% extends'base.html.twig' %} {% block body %} <table> <tr> <th>Nume</th> <th>Culoare</th> <th>Marime</th> <th>Pret</th> <th colspan="3">Actions</th> </tr> {% for key in flowers %} <tr> <td>{{ key.nume }}</td> <td>{{ key.culoare }}</td> <td> {{ key.marime }}</td> <td>{{ key.pret }}</td> <td><a href="{{ app.request.baseUrl() }}/show/{{key.id}}">View</a> <a href="{{ app.request.baseUrl() }}/edit/{{key.id}}">Edit</a> <a href="{{ app.request.baseUrl() }}/delete/{{key.id}}" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a> </td> </tr> {% endfor %} </table> <a href="{{ app.request.baseUrl() }}/data/add">Insert a record</a> {% endblock %}
  • 3.
    Controller-ul DataController ……………………………… /** * @Route("/delete/{id}") *@Method({"GET", "POST"}) */ public function deleteAction($id){ $em=$this->getDoctrine()->getManager(); $flower = $this->getDoctrine()-> getRepository(Flower::class)->find($id); $em->remove($flower); $em->flush(); return $this->redirectToRoute('data'); }