custom fields
Opened this issue · 0 comments
srakl commented
i have this in my actionRegister()
which i extended the Da\User\Controller\RegistrationController
$this->on(FormEvent::EVENT_AFTER_REGISTER, function ($event) {
$form = $event->getForm();
$user = User::find()->where(['email' => $form->email])->one();
$profile = $user->profile;
$profile->firstname = $form->firstname;
$profile->lastname = $form->lastname;
if (!$profile->save()) {
print_r($profile->getErrors()); die;
}
});
when registering, a new user the email
, password_hash
, auth_key
, registered_ip
and password_changed_at
columns are filled.
The firstname
and lastname
is not stored in the profile
table, and created_at in the user table is 0000-00-00 00:00:00
i added this to the user model
class User extends BaseUser
{
public $firstname;
public $lastname;
...
}
and this to the profile model
class Profile extends BaseProfile
{
public $firstname;
public $lastname;
...
}
in both user and profiles models that i extended i have this
'firstnameLength' => ['firstname', 'string', 'max' => 255],
'lastnameLength' => ['lastname', 'string', 'max' => 255],
i tried saving to firstname and lastname to profile table, and user table too. both failed. What am i missing? why doesn't save()
work? i even tried save(false)
too. Im not getting any errors. Please help. thanks