yii2 高级模板扩展用户模型并且没有保存数据

yii2 advanced template extend User model and no data saved

我最近刚下载了 yii2 高级模板,并在前端模块中创建了新模型,在 "common/models" 中扩展了用户,就像这样

class UsUser extends User
{

}

class SignupForm extends Model
{      

/**
 * Signs user up.
 *
 * @return User|null the saved model or null if saving fails
 */
public function signup()
{
    if ($this->validate()) {
        $user = new UsUser();
        $user->username = $this->username;
        $user->email = $this->email;
        $user->setPassword($this->password);
        $user->generateAuthKey();
        $user->save();
        return $user;
    }

    return null;
}

当我注册时,没有任何错误,只是被重定向到主页,但没有数据被插入到数据库中。我没有在我的模型(User 或 UsUser)中使用 public 属性,正如 Tal V. 在此处指定的那样(Yii2 active record model not saving data。因此 UsUser 中只有 @属性 注释。

可能是我做的不对,或者还有什么需要注意的地方,谁能帮忙指出一下?非常感谢。

class SignupForm extends Model
{

    /**
     * Signs user up.
     *
     * @return User|null the saved model or null if saving fails
     */
    public function signup()
    {
        if ($this->validate())
        {
            $user           = new UsUser();
            $user->username = $this->username;
            $user->email    = $this->email;
            $user->setPassword($this->password);
            $user->generateAuthKey();
            //IF UsUser MODEL IS VALID THEN SAVE DATA
            if ($user->validate())
            {
                $user->save(false);
                return $user;
            }
            //IF UsUser MODEL IS NOT VALID THEN PRINT THE ERRORS.SO YOU CAN CHECK WHAT ARE THE ERRORS IN MODEL
            else
            {
                echo "<pre>";
                print_r($user->getErrors());
                echo "</pre>";
            }
        }
    }

}