yii2mod / yii2-user

Flexible user registration and authentication module for Yii2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

class myUser extends UserModel do not executes ::afterSave() method

dkipkaev opened this issue · comments

Hi. I have the following simple code

class User extends \yii2mod\user\models\UserModel
{
    public function getUsermeta()
    {
        return $this->hasOne(UserMeta::class, ['user_id' => 'id']);
    }

    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);
        if ($insert) {
            $usermeta = new UserMeta();
            $usermeta->link('user', $this);
        }
    }
}

When creating a new user (config.php: 'identityClass' => 'app\models\User'), the function afterSave() do not want to be executed.
Any thoughts to resolve this?

Ok, I found who is responsible for that

    public function signup()
    {
        ...
        $this->user = new UserModel();
        ...
        return $this->user->save() ? $this->user : null;
    }

SignupForm.php