Answer the question
In order to leave comments, you need to log in
How to create a Yii2-user relationship with my table?
I installed Yii2-user in my project, created my own contact table which has "id", "user_id", "phone", "email", "skype", "adress", "index" columns. Interested in the question, how to link the standard table "User" from yii2-user with my table "contact"?
Those. I need to be able to contact an authorized user on the site and get his connection with the contact table (for output, editing, etc.)
Answer the question
In order to leave comments, you need to log in
And unless through relational communication does not approach? It needs to be added to your project model. If you have an extension, then you need to redefine identityClass to your model in the project.
'components' => [
'user' => [
'identityClass' => 'app\models\User',
],
],
/**
* @return \yii\db\ActiveQuery
*/
public function getСontact()
{
return $this->hasOne(Сontact::className(), ['user_id' => 'id']);
}
$model = User::find()->all();
$model->contact;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question