Skip to content

Commit

Permalink
added order's delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
brikou committed Jul 28, 2011
1 parent b7ae910 commit 891cf03
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
24 changes: 24 additions & 0 deletions Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,28 @@ public function editAction($id)
'order' => $order,
);
}

/**
* @Route("/delete/{id}")
* @Template()
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getEntityManager();

$order = $em->find('AcmePizzaBundle:Order', $id);

if (!$order) {
throw $this->createNotFoundException("Invalid order.");
}

foreach ($order->getItems() as $item) {
$em->remove($item);
}

$em->remove($order);
$em->flush();

return $this->redirect($this->generateUrl('acme_pizza_order_list'));
}
}
4 changes: 1 addition & 3 deletions Resources/views/Order/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
</tfoot>
</table>

{#
<a href="{{ path("acme_pizza_order_edit", {"id": order.id}) }}">Edit</a>
#}
<a href="{{ path("acme_pizza_order_show", {"id": order.id}) }}">Show</a>

<hr />

Expand Down
9 changes: 6 additions & 3 deletions Resources/views/Order/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
</tfoot>
</table>

{#
<a href="{{ path("acme_pizza_order_edit", {"id": order.id}) }}">Edit</a>
#}
<ul>
{#
<li><a href="{{ path("acme_pizza_order_edit", {"id": order.id}) }}">Edit</a></li>
#}
<li><a href="{{ path("acme_pizza_order_delete", {"id": order.id}) }}">Delete</a></li>
</ul>

{% endblock %}

0 comments on commit 891cf03

Please sign in to comment.