Answer the question
In order to leave comments, you need to log in
How to make a redirect in yii2?
There is a form
<?php $form = ActiveForm::begin(); ?>
<?= Html::activeTextInput($model, 'sum', [ 'class' => 'form-control','name' => 'sumer', 'value' => '']) ?>
<?= Html::submitButton($model->isNewRecord ? Yii::t('frontend', 'Transfer') : Yii::t('frontend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
public function actionTrans()
{
$model = new Transactions();
if ($model->load(Yii::$app->request->post()) ) {
return $this->redirect(['create']);
} else {
return $this->render('trans', [
'model' => $model,
]);
}
}
<?php
$su = ($_POST['sumer']);
echo $su;
?>
Answer the question
In order to leave comments, you need to log in
You misunderstand the essence of the POST request, the framework has nothing to do with it. If you want to transfer some data from one request to another (in the case of Yii, this is between two actions), then you will have to save it somewhere. As an option, I can suggest storing them in the session Yii::$app->session->set()// ->get()
and actionCreate()
passing this data to the view
return $this->render('create', [
'data1' => Yii::$app->session->get('someData1'),
.....
],);
if ($model->load(Yii::$app->request->post()) ) { // Здесь вы грузите
// Делаете что хотите
$model->save(); // Сохранили
return $this->redirect(['create']);
}
actionCreate()
) pull it out of the base as the last element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question