Answer the question
In order to leave comments, you need to log in
Why method does not see session in Yii2?
When requested in the actionTrans method, a session with a variable is created. Further, in the view there is a transfer to another page actionCreate, but here the method does not see the $count variable. It is in the method, and not in the views of the actionCreate method.
public function actionTrans()
{
$session = Yii::$app->session;
$session->open();
$pass = 1111;
$session->set('counter', "$pass");
$count = $session->get('counter');
if ($model->load(Yii::$app->request->post()) ) {
return $this->redirect(['create']);
} else {
return $this->render('trans', [
'model' => $model,
]);
}
}
public function actionCreate()
{
}
Answer the question
In order to leave comments, you need to log in
Did it and it worked
public function actionCreate()
{
$session = Yii::$app->session;
$count = $session->get('counter');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question