@
@
@Insout2017-03-04 23:42:04
Yii
@Insout, 2017-03-04 23:42:04

Yii2: Why is data not being written to the session?

Good afternoon.
Why is data not being written to the session?

$session = Yii::$app->session;
$session->open();
$session->set('language', 'ru');
print_r($session);

The response looks like this (nothing got into the session):
yii\web\Session#1
(
    [flashParam] => '__flash'
    [handler] => null
    [yii\web\Session:_cookieParams] => [
        'httponly' => true
    ]
    [yii\web\Session:_hasSessionId] => null
    [yii\base\Component:_events] => []
    [yii\base\Component:_behaviors] => null
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-03-05
_

Good morning.
Everything is written beautifully.

$session = Yii::$app->session;
$session->open();
if($session->isActive){
    $session->set('language', 'ru');
}

if($session->has('language')){
   echo $session['language'];
}else{
   echo 'no';
}

More here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question