Answer the question
In order to leave comments, you need to log in
How to autosave in Yii2?
Show with an example how to make autosave if not difficult)
I roughly know that I need to apply behaviors, but I just can’t understand how it works.
For example, there is a behaviors controller with an action:
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionCreate()
{
$model = new History();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->history_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
<?php $form = ActiveForm::begin(); ?>
<?= Html::activeTextInput($model, 'ik_co_id', ['class'=>'form-item req', 'value' => "{$_POST['ik_co_id']}"]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('frontend', 'Create') : Yii::t('frontend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
Answer the question
In order to leave comments, you need to log in
In your example, behavior describes only restrictions on the type of request (GET, POST) for actions. Can you elaborate on what exactly you mean by autosave?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question