beforeSave() edit the record before saving

data in the birthday field is entered manually and i need to save the last 4 characters from the 10 entered characters to the database, but i can not edit the record before saving. Please help!!




class SignupForm extends Model

{


    public $username;

    public $email;

    public $password;

    public $birthday;

    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            ['username', 'trim'],

            ['username', 'required'],

            ['username', 'unique', 'targetClass' => '\app\models\User', 'message' => 'This username has already been taken.'],

            ['username', 'string', 'min' => 2, 'max' => 255],

            ['email', 'trim'],

            ['email', 'required'],

            ['email', 'email'],

            ['email', 'string', 'max' => 255],

            ['email', 'unique', 'targetClass' => '\app\models\User', 'message' => 'This email address has already been taken.'],

//            ['password', 'required'],

//            ['password', 'string', 'min' => 3],

            ['birthday', 'required'],

            ['birthday', 'string', 'min' => 10, 'max' => 10]

        ];

    }


    /**

     * Signs user up.

     *

     * @return User|null the saved model or null if saving fails

     */

    public function signup()

    {


        if (!$this->validate()) {

            return null;

        }


        $user = new User();

        $user->username = $this->username;

        $user->email = $this->email;

        $user->setPassword($this->birthday);

        $user->generateAuthKey();

        return $user->save() ? $user : null;

    }


    public function beforeSave($insert)

    {

        if (parent::beforeSave($insert)) {

            $this->birthday = substr('$birthday', 6,4);

            return true;

        } else {

            return false;

        }

    }




}



should not this be like so


 public function beforeSave($insert)

    {

        if (parent::beforeSave($insert)) {

            $this->birthday = substr($this->birthday, 6,4);

            return true;

        } else {

            return false;

        }

    }