S
S
Sergey2015-09-09 11:43:19
Yii
Sergey, 2015-09-09 11:43:19

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

3 answer(s)
S
Sergey, 2015-09-10
@alekskondr

Did it and it worked

public function actionCreate()
    {
        $session = Yii::$app->session;
            $count = $session->get('counter');
}

T
Talgat Baltasov, 2015-09-09
@talgatbaltasov

yiiframework.ru/forum/viewtopic.php?t=23221 see this

L
Lander, 2015-09-09
@usdglander

$session->open(); erase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question