Skip to content

Commit

Permalink
enhanced demo and added debug tool to composer package
Browse files Browse the repository at this point in the history
  • Loading branch information
vanting committed Oct 29, 2013
1 parent 169dae6 commit cf2a0ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions app/controllers/demo.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,29 @@

$guest = R::dispense('guest');

$name = $app->request()->post('name');
$name = $app->request->post('name');
if (empty($name))
$name = 'anonymous';

$guest->name = $name;
$guest->message = $app->request()->post('message');

$guest->message = $app->request->post('message');
$guest->ip = $app->request->getIp();

// prepare to delete old comments
$yesterday = date('Y-m-d' , strtotime('-1 day'));

// start transaction
R::begin();
try {
R::exec('DELETE FROM guest WHERE modify_date < ?', array($yesterday));
R::store($guest);
R::commit();
$app->flash('success', 'Nice to hear from you!');
} catch (Exception $e) {
R::rollback();
$app->flash('error', 'Oops... seems something goes wrong.');
}
$app->redirect($app->request()->getReferrer());
$app->redirect($app->request->getReferrer());
})->name('guest_comment');

//PUT route
Expand Down
4 changes: 3 additions & 1 deletion app/views/demo.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
<table class="table table-striped table-condensed table-hover">
<thead>
<tr>
<th>Date</th>
<th>Who</th>
<th>Message</th>
</tr>
</thead>
<tbody>
{% for guest in guests %}
<tr>
<td>{{ guest.modify_date }} @{{ guest.name }}</td>
<td>{{ guest.modify_date }}</td>
<td>{{ guest.name }} @{{ guest.ip }}</td>
<td>{{ guest.message }}</td>
</tr>
{% endfor %}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"slim/views":"0.1.*",
"twig/twig": "1.*",
"twig/extensions": "*",
"gabordemooij/redbean": "*"
"gabordemooij/redbean": "*",
"raveren/kint": "dev-master"
},
"config": {
"preferred-install": "dist"
Expand Down

0 comments on commit cf2a0ce

Please sign in to comment.