Permalink
Browse files

Ajout de flash message

  • Loading branch information...
1 parent c9bcc93 commit 43d86f82e489dcb6cb761e8664a0c8f40158604f Maxime AILLOUD committed May 23, 2012
Showing with 26 additions and 3 deletions.
  1. +1 −0 src/app.php
  2. +14 −3 src/controllers.php
  3. +11 −0 views/index.twig
View
@@ -22,6 +22,7 @@
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\SymfonyBridgesServiceProvider());
+$app->register(new Silex\Provider\SessionServiceProvider());
if(in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
View
@@ -166,9 +166,20 @@
;
$app->post('/add_category', function (Request $request) use($app) {
- $spendingCategory = new \PayMeBack\Model\SpendingCategory();
- $spendingCategory->setTitle($app['request']->get('category_title'));
- $spendingCategory->save();
+ $app['session']->start();
+
+ try
+ {
+ $spendingCategory = new \PayMeBack\Model\SpendingCategory();
+ $spendingCategory->setTitle($app['request']->get('category_title'));
+ $spendingCategory->save();
+
+ $app['session']->setFlash('success', 'Catégorie crée avec succès');
+ }
+ catch(\Exception $exception)
+ {
+ $app['session']->setFlash('error', 'Erreur lors de l\'ajout de la catégorie');
+ }
return $app->redirect($app['url_generator']->generate('homepage'));
});
View
@@ -98,6 +98,17 @@
<section class="span10">
<section class="row-fluid">
<div class="span12">
+ {% for key, flash in app.session.getFlashes() %}
+ <div class="alert alert-{{ key }}">
+ <button class="close" data-dismiss="alert">×</button>
+ {{ flash }}
+ </div>
+ {% endfor %}
+ {% for flashMessage in app.session.flashbag.get('notice') %}
+ <div class="flash-notice">
+ {{ flashMessage }}
+ </div>
+ {% endfor %}
<form action="{{ app.request.basepath }}/add_category" class="form-inline well" method="post" accept-charset="utf-8">
<input placeholder="Ajouter une catégorie" type="text" name="category_title" required="required" />
<input type="submit" class="btn" value="Ajouter" />

0 comments on commit 43d86f8

Please sign in to comment.