Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
flash added to Create and Update actions
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 4, 2016
1 parent e4bd422 commit 2780bd9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,38 @@ class ItemController extends Controller
return [
'index' => [
'class' => 'yii2tech\admin\actions\Index',
'modelClass' => $this->modelClass,
'searchModelClass' => 'app\models\ItemSearch',
'newSearchModel' => function () {
return new ItemSearch();
},
],
'view' => [
'class' => 'yii2tech\admin\actions\View',
'modelClass' => 'app\models\Item',
],
'create' => [
'class' => 'yii2tech\admin\actions\Create',
'modelClass' => 'app\models\Item',
],
'update' => [
'class' => 'yii2tech\admin\actions\Update',
'modelClass' => 'app\models\Item',
],
'delete' => [
'class' => 'yii2tech\admin\actions\Delete',
'modelClass' => 'app\models\Item',
],
];
}

public function findModel($id)
{
if (($model = Item::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

public function newModel()
{
return new Item();
}
}
```

Expand Down
6 changes: 6 additions & 0 deletions actions/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Create extends Action
* ```
*/
public $loadDefaultValues = false;
/**
* @var string|array|null flash message to be set on success.
* @see Action::setFlash() for details on how setup flash.
*/
public $flash;


/**
Expand Down Expand Up @@ -90,6 +95,7 @@ public function run()
return ActiveForm::validate($model);
}
if ($model->save()) {
$this->setFlash($this->flash, ['model' => $model]);
return $this->controller->redirect($this->createReturnUrl('view', $model));
}
} else {
Expand Down
6 changes: 6 additions & 0 deletions actions/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class Update extends Action
* @var string name of the view, which should be rendered
*/
public $view = 'update';
/**
* @var string|array|null flash message to be set on success.
* @see Action::setFlash() for details on how setup flash.
*/
public $flash;


/**
Expand All @@ -46,6 +51,7 @@ public function run($id)
return ActiveForm::validate($model);
}
if ($model->save()) {
$this->setFlash($this->flash, ['id' => $id, 'model' => $model]);
return $this->controller->redirect($this->createReturnUrl('view', $model));
}
}
Expand Down
1 change: 1 addition & 0 deletions actions/VariationCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function run()
return $this->performAjaxValidation($model);
}
if ($model->save()) {
$this->setFlash($this->flash, ['model' => $model]);
return $this->controller->redirect($this->createReturnUrl('view', $model));
}
} else {
Expand Down
1 change: 1 addition & 0 deletions actions/VariationUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function run($id)
return $this->performAjaxValidation($model);
}
if ($model->save()) {
$this->setFlash($this->flash, ['id' => $id, 'model' => $model]);
return $this->controller->redirect($this->createReturnUrl('view', $model));
}
}
Expand Down

0 comments on commit 2780bd9

Please sign in to comment.