Hi im learning Yii 2, but i have a question because i do not undestood, in the next code from Yii from beginners.
The function getUser() retrive the information from the database using $this->hasOne
But my question is how in getUserName "$this->user->username;" can give me the username from the model User if in this code i do not indicate what is the ID for that user, i do not undestood this magic method
Warm Regards
<?php
namespace frontend\models;
use Yii;
use common\models\User;
class Perfil extends \yii\db\ActiveRecord
{
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'nombre' => 'Nombre',
];
}
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
public function getUserName()
{
return $this->user->username;
}
}