Related data in ActiveView

Hello,

please, a little help.

In DetailView it’s simple getting data of a related table:


<?= $form->field($model, 'userid')->textInput(['maxlength' => 255, 'value' => 'user.username', 'readonly' => true]) ?>

But I can’t figure out how to obtain the same in Activeform:


<?= $form->field($model, 'userid')->textInput(['maxlength' => 255, 'value' => 'this don't work: user.username', 'readonly' => true]) ?>

This in model:


    public function getUser()

    {

        return $this->hasOne(User::className(), ['id' => 'userid']);

    }

Edit. Ok, I got it.

in controller:




        $model = $this->findModel($id);

		$usr = $model->user;

        ...

            return $this->render('update', [

                'model' => $model,

                'usr' => $usr,

in the view:


    <?= $this->render('_forupdate', [

        'model' => $model,

		'utente' => $utente

    ]) ?>

    ...

    <?= $form->field($usr, 'username')->textInput(['maxlength' => 255, 'readonly' => true]) ?>

Hi,

Have you declared "public $username;" in your model?

You’re right, but no, it is not declared. But I think (maybe) because this object is already public - I use amnah user plugin - and some variables can be reach from everywere.