Thanks for the answer I got my way but following how to add field from prfile to registration after the user registers his profile is not being saved; here is what I did:
a)RegistrationForm Model (override from RegistrationForm)
public function loadAttributes()
{
// here is the magic happens
$this->user->setAttributes([
'email' => $this->email,
'username' => $this->username,
'password' => $this->password,
]);
/** @var Profile $profile */
$profile = \Yii::createObject(Profile::className());
$profile->scenario = 'signup';
$profile->setAttributes([
'gravatar_email' => $this->email,
'pays' => $this->pays,
'ville'=>$this->ville,
'sexe'=>$this->sexe,
'name'=>$this->name,
'location'=>$this->location,
]);
$this->user->setProfile($profile);
}
public function register()
{
if (!$this->validate()) {
return false;
}
$this->loadAttributes();
return $this->user->register();
}
}
User Model(override from user Model)
public function afterSave($insert, $changedAttributes)
{
if ($insert) {
//If I don't put this first line the user_id in insert statement is empty causing
//SQL Integrity error
$this->profile->user_id= $this->id;
$this->profile->save();
}
// parent::afterSave($insert, $changedAttributes);
}
public function setProfile(Profile $profile){
$this->profile = \Yii::createObject(Profile::className());
$this->profile = $profile;
}
I even tried to do this in RegistrationFor:
public function register()
{
if (!$this->validate()) {
return false;
}
$this->user->setAttributes([
'email' => $this->email,
'username' => $this->username,
'password' => $this->password
]);
$valeur = $this->user->register();
if($valeur){
/** @var Profile $profile */
$profile = \Yii::createObject(Profile::className());
$profile->scenario='signup';
$profile->setAttributes([
'pays' => $this->pays,
'ville'=>$this->ville,
'sexe'=>$this->sexe,
'name'=>$this->name,
'location'=>$this->location,
]);
$profile->save();
}
return $valeur;
}
}
But still if I check the profile table nothing is being save a part from gravatar email which is being done in aftersave of user model; I don’t figure out easly where my codes are messing up.
If there is a complete example until showing how the profile information on the registrationForm will be saved that can really help or An idea.