In my form I wanna get the username instead of the user_id, I'm getting "Trying to get property of non-object", how do I properly get the Username from the user table?
<?= $form->field($model, 'user_id')->textInput(
[
//'value' => Yii::$app->user->getId(),
'value' => $model->user->username,
'readonly' => true,
'style' => 'width:400px'
]
)?>
Here's the model of this form
public function getUserType(){
//Related model Class Name
//related column name as select
return $this->hasOne(User::className() ,['id' => 'user_id'])->select('type')->scalar();
}