Skip to content

Commit

Permalink
new validate
Browse files Browse the repository at this point in the history
  • Loading branch information
teo2022 committed Jun 24, 2017
1 parent 0ed389a commit 0d706cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
18 changes: 4 additions & 14 deletions controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,8 @@ public function actionCreate()
{
$model = new <?= $modelClass ?>();

if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
if ($model->save()) {
return $this->redirect(['index']);
} else {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->renderAjax('create', [
'model' => $model,
Expand All @@ -141,13 +136,8 @@ public function actionUpdate(<?= $actionParams ?>)
{
$model = $this->findModel(<?= $actionParams ?>);

if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
if ($model->save()) {
return $this->redirect(['index']);
} else {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->renderAjax('update', [
'model' => $model,
Expand Down
1 change: 1 addition & 0 deletions views/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<?= "<?php " ?>$form = ActiveForm::begin([
'id' => 'order-form',
'enableAjaxValidation' => true,
'validationUrl' => ['<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>/validate'],
]); ?>

<?php foreach ($generator->getColumnNames() as $attribute) {
Expand Down

0 comments on commit 0d706cf

Please sign in to comment.