Skip to content

Commit

Permalink
added order_show + flash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
brikou committed Jul 27, 2011
1 parent a7b8985 commit b7ae910
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 5 deletions.
23 changes: 21 additions & 2 deletions Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ public function indexAction()

if ($form->isValid()) {

$em->persist($factory->make());
$em->persist($order = $factory->make());
$em->flush();

return $this->redirect($this->generateUrl('acme_pizza_order_list'));
$this->get('session')->setFlash('success', 'New order were saved!');

return $this->redirect($this->generateUrl('acme_pizza_order_show', array(
'id' => $order->getId(),
)));
}
}

Expand All @@ -64,6 +68,21 @@ public function listAction()
return array('orders' => $orders);
}

/**
* @Route("/show/{id}")
* @Template()
*/
public function showAction($id)
{
$order = $this->getDoctrine()->getEntityManager()->find('AcmePizzaBundle:Order', $id);

if (!$order) {
throw $this->createNotFoundException('The order does not exist');
}

return array('order' => $order);
}

/**
* @Route("/edit/{id}")
* @Template()
Expand Down
2 changes: 2 additions & 0 deletions Controller/PizzaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function editAction($id = null)
$em->persist($pizza);
$em->flush();

$this->get('session')->setFlash('success', 'New pizza was saved!');

return $this->redirect($this->generateUrl('acme_pizza_pizza_list'));
}
}
Expand Down
33 changes: 33 additions & 0 deletions Resources/public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,36 @@ table ul {
display: inline-block; }
table ul li:not(:last-child):after {
content: " | "; }

.error, .alert, .notice, .success, .info {
padding: 0.8em;
margin-bottom: 1em;
border: 2px solid #ddd; }

.error, .alert {
background: #fbe3e4;
color: #8a1f11;
border-color: #fbc2c4; }
.error a, .alert a {
color: #8a1f11; }

.notice {
background: #fff6bf;
color: #514721;
border-color: #ffd324; }
.notice a {
color: #514721; }

.success {
background: #e6efc2;
color: #264409;
border-color: #c6d880; }
.success a {
color: #264409; }

.info {
background: #d5edf8;
color: #205791;
border-color: #92cae4; }
.info a {
color: #205791; }
42 changes: 39 additions & 3 deletions Resources/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import "toucan-0.1.9";
@import "css3-please";

// -----------------------------------------------------------------------------
// ---------------------------------------------------------------------------

body {
width: 940px;
Expand All @@ -24,7 +24,7 @@ form .error ul {
color: #8A1F11;
}

// -----------------------------------------------------------------------------
// ---------------------------------------------------------------------------

@mixin indent($i) {
$step: 40px;
Expand Down Expand Up @@ -59,7 +59,7 @@ form {
}
}

// -----------------------------------------------------------------------------
// ---------------------------------------------------------------------------

table ul {
list-style: none;
Expand All @@ -73,3 +73,39 @@ table ul {
}
}
}

// ---------------------------------------------------------------------------

.error, .alert, .notice, .success, .info {
padding: 0.8em;
margin-bottom: 1em;
border: 2px solid #ddd;
}
.error, .alert {
background: #fbe3e4;
color: #8a1f11;
border-color: #fbc2c4;
a {
color:#8a1f11; }
}
.notice {
background: #fff6bf;
color: #514721;
border-color: #ffd324;
a {
color:#514721; }
}
.success {
background: #e6efc2;
color: #264409;
border-color: #c6d880;
a {
color:#264409; }
}
.info {
background: #d5edf8;
color: #205791;
border-color: #92cae4;
a {
color:#205791; }
}
54 changes: 54 additions & 0 deletions Resources/views/Order/show.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{% extends "AcmePizzaBundle::layout.html.twig" %}

{% block title parent() ~ " - Order - Show" %}

{% block content %}

<h2>Order #{{ order.id }}</h2>

<dl>
<dt>Name</dt>
<dd>{{ order.customer.name }}<dd>

<dt>Street</dt>
<dd>{{ order.customer.street }}<dd>

<dt>City</dt>
<dd>{{ order.customer.city }}<dd>

<dt>Phone</dt>
<dd>{{ order.customer.phone }}<dd>
</dl>

<table>
<thead>
<tr>
<th>Pizza</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% for item in order.items %}
<tr>
<td>{{ item.pizza.name }}</td>
<td>{{ item.count }}</td>
<td>{{ item.pizza.price }}</td>
<td>{{ item.total }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th colspan="3">Total</th>
<td>{{ order.total }}</td>
</tr>
</tfoot>
</table>

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

{% endblock %}
6 changes: 6 additions & 0 deletions Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

<hr />

{% if app.session.hasFlash('success') %}
<div class="success">
{{ app.session.flash('success') }}
</div>
{% endif %}

{% block content %}
{% endblock %}

Expand Down

0 comments on commit b7ae910

Please sign in to comment.