Yii 2:将会话变量传递给输入

How do I pass the session variable userid to a text input? Using Yii::app->session?

loginform model of my application

 $session = Yii::$app->session;
 $session->set('userid',  $this->getUser($this->email, 'id'));
 $session->set('firstname',  $this->getUser($this->email, 'fname'));

view/ form

<?= $form->field($model, 'name')->textInput(['value' => Yii::$app->session['email']]) ?>    

You should just pass it as Yii::$app->session->get('userid')->id.

You were calling the email instead of userid. You can read more about sessions it in the documentation itself. Please, let me know if there is anything unclear.

The problem is when you pass the value to the session. Because the value you are passing is an object, but there is a solution and it is simple.

$form->field($model, 'name')->textInput([
    'value' => Yii::$app->session->get('userid')->id
]);

I am not entirely clear why you want to expressly set the session user ID when Yii has a built-in way to retrieve the user ID.

Yii::$app->user->getId();

The above will return the user ID without the need for you to manually set the session user ID.