dth981485742 2018-11-09 06:43
浏览 97
已采纳

如何根据用户登录并在yii2中的表格列/字段中显示来调用数据库中的数据?

i want to display the username based on user that login to the application and put it inside field form (username)

this is code for my form
<?= $form->field($model, 'username')->textInput(['maxlength' => true])?>

this is code for calling the username based on the login user

<?=Yii::$app->user->identity->username ?>

but i dont know how to put the username inside the textinput

  • 写回答

2条回答 默认 最新

  • douturan1807 2018-11-09 07:42
    关注

    You should set a necessary value in the model object that passes to ActiveFrom widget:

    <?= $model->username = Yii::$app->user->identity->username; ?>
    <?= $form->field($model, 'username')->textInput(['maxlength' => true]); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?