Skip to content

Commit

Permalink
Added: setFlash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gugoan committed Apr 26, 2015
1 parent de8e522 commit 1bd8578
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion controllers/CashbookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public function actionCreate()
$path = $model->getImageFile();
$file->saveAs($path);
}
return $this->redirect(['view', 'id'=>$model->id]);
Yii::$app->session->setFlash("Entry-success", Yii::t("app", "Entry successfully included"));
return $this->redirect(['index']);
} else {
// error in saving model
}
Expand Down Expand Up @@ -129,6 +130,7 @@ public function actionUpdate($id)
$path = $model->getImageFile();
$file->saveAs($path);
}
Yii::$app->session->setFlash("Entry-success", Yii::t("app", "Entry updated"));
return $this->redirect(['view', 'id'=>$model->id]);
} else {
// error in saving model
Expand Down Expand Up @@ -156,6 +158,7 @@ public function actionDelete($id)
Yii::$app->session->setFlash('error', 'Error deleting image');
}
}
Yii::$app->session->setFlash("Entry-success", Yii::t("app", "Entry successfully deleted"));
return $this->redirect(['index']);
}

Expand Down
3 changes: 3 additions & 0 deletions controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function actionCreate()
$model->user_id = Yii::$app->user->identity->id;

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash("Category-success", Yii::t("app", "Category successfully included"));
return $this->redirect(['index']);
} else {
return $this->render('create', [
Expand All @@ -103,6 +104,7 @@ public function actionUpdate($id)
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash("Category-success", Yii::t("app", "Category updated"));
return $this->redirect(['index']);
} else {
return $this->render('update', [
Expand All @@ -120,6 +122,7 @@ public function actionUpdate($id)
public function actionDelete($id)
{
$this->findModel($id)->delete();
Yii::$app->session->setFlash("Category-success", Yii::t("app", "Category successfully deleted"));

return $this->redirect(['index']);
}
Expand Down
6 changes: 6 additions & 0 deletions messages/pt/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@
'No entries found!' => 'Nenhum lançamento encontrado!',
'Basic Information' => 'Informações Básicas',
'Additional' => 'Complementares',
'Entry successfully included' => 'Lançamento incluído com sucesso',
'Entry updated' => 'Lançamento atualizado',
'Entry successfully deleted' => 'Lançamento excluído com sucesso',
// category model
'Hex Color' => 'Hex Cor',
'Category successfully included' => 'Categoria incluída com sucesso',
'Category updated' => 'Categoria atualizada',
'Category successfully deleted' => 'Categoria excluído com sucesso',
// view / site
'Overview' => 'Visão Geral',
'Monthly Summary' => 'Resumo Mensal',
Expand Down
7 changes: 7 additions & 0 deletions views/cashbook/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
<?= Html::a('<i class="fa fa-plus"></i> '.Yii::t('app', 'Entry').'', ['/cashbook/create'], ['class'=>'btn btn-primary grid-button btn-sm pull-right']) ?>
</h2>
<hr/>
<?php if ($flash = Yii::$app->session->getFlash("Entry-success")): ?>

<div class="alert text-success">
<p><em><?= $flash ?></em></p>
</div>

<?php endif; ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'tableOptions' => ['class'=>'table table-striped table-hover'],
Expand Down
6 changes: 6 additions & 0 deletions views/cashbook/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
</div>
</h2>
<hr/>
<?php if ($flash = Yii::$app->session->getFlash("Entry-success")): ?>

<div class="alert text-success">
<p><em><?= $flash ?></em></p>
</div>

<?php endif; ?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
Expand Down
7 changes: 7 additions & 0 deletions views/category/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
<?= Html::a('<i class="fa fa-plus"></i> '.Yii::t('app', 'Category').'', ['/category/create'], ['class'=>'btn btn-primary grid-button btn-sm pull-right']) ?>
</h2>
<hr/>
<?php if ($flash = Yii::$app->session->getFlash("Category-success")): ?>

<div class="alert text-success">
<p><em><?= $flash ?></em></p>
</div>

<?php endif; ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
Expand Down

0 comments on commit 1bd8578

Please sign in to comment.