Is the relationship between the 2 models already set up? I mean, does your User model have a hasMany relation named "factures" and does your Facture model has a hasOne relation named "user"?
When you have an appropriate foreign key constraint between the 2 tables, Gii should have already generated these relation methods:
/* in User model */
/**
* @return \yii\db\ActiveQuery
*/
public function getFactures()
{
return $this->hasMany(Facture::className(), ['userid' => 'id']);
}
/* in Facture model */
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasMany(User::className(), ['userid' => 'id']);
}
If not yet, then you should write them manually, or, preferably re-run Gii’s model generator after setting up the foreign key constraint.
If yes, then you are ready to go.
You can access the facture models that belongs to a user like the following:
$user = User::find()->...->one();
foreach( $user->factures as $facture) {
echo $facture->facture_name;
}
If you are using DetailView, something like the following will do:
<?= DetailView::widget([
'model' => $model, // User
'attributes' => [
'id',
'username',
'email',
[
'label' => 'Factures',
'value' => function ($model) {
$names = [];
foreach( $model->factures as $facture) {
$names[] = $facture->facture_name;
}
return implode("<br>", $names);
},
],
],
]) ?>