noobkoder
(Smurfdusk)
1
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'
]
)?>
noobkoder
(Smurfdusk)
2
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,
softark
(Softark)
3
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".