How do I change id into name

In my form I wanna get the user’s username instead of the user_id how do I do that in my form?




    <?= $form->field($model, 'user_id')->textInput(

      [

        'value' => Yii::$app->user->getId(),

        'value' => 'user.user_username', //I tried this but it doesn't display the username

        'readonly' => true,

        'style' => 'width:400px'

      ]

      )?>



So I tried a different way of getting the username but I’m getting an error Trying to get property of non-object


'value' => $model->user->username,

Hi noobkoder,

What does "$model" refer to in your code? Is it the User model? Then you could simply access the username by "$model->username".