Closed cobabikin closed 7 years ago
my model User related model UserProfile code models User
`public static function tableName() { return '{{%user}}'; }
public function attributeLabels() { return [ 'username' => Yii::t('common', 'Username'), 'email' => Yii::t('common', 'Email'), 'status' => Yii::t('common', 'Status'), 'created_at' => Yii::t('common', 'Created at'), 'updated_at' => Yii::t('common', 'Updated at'), 'action_at' => Yii::t('common', 'Last action at'), ]; }
public function getUserProfile() { return $this->hasOne(UserProfile::className(), ['user_id' => 'id']); }`
and code model UserProfile ` public static function tableName() { return '{{%user_profile}}'; }
public function behaviors() { return [ 'uploadBehavior' => [ 'class' => UploadBehavior::className(), 'attributes' => [ 'avatar_path' => [ 'path' => '@storage/avatars', 'tempPath' => '@storage/tmp', 'url' => Yii::getAlias('@storageUrl/avatars'), ], ], ], ]; } public function attributeLabels() { return [ 'firstname' => Yii::t('common', 'Firstname'), 'lastname' => Yii::t('common', 'Lastname'), 'birthday' => Yii::t('common', 'Birthday'), 'avatar_path' => Yii::t('common', 'Avatar'), 'gender' => Yii::t('common', 'Gender'), 'website' => Yii::t('common', 'Website'), 'other' => Yii::t('common', 'Other'), ]; }`
You need to create the following method in your model:
public function getAvatar() { // your custom code }
my model User related model UserProfile code models User
`public static function tableName() { return '{{%user}}'; }
public function attributeLabels() { return [ 'username' => Yii::t('common', 'Username'), 'email' => Yii::t('common', 'Email'), 'status' => Yii::t('common', 'Status'), 'created_at' => Yii::t('common', 'Created at'), 'updated_at' => Yii::t('common', 'Updated at'), 'action_at' => Yii::t('common', 'Last action at'), ]; }
public function getUserProfile() { return $this->hasOne(UserProfile::className(), ['user_id' => 'id']); }`
and code model UserProfile ` public static function tableName() { return '{{%user_profile}}'; }