We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to call save() or update() without validating.?

hi all, I had written a validation function which takes 2 parameters...validation is working fine....but when i try use save() or update() function then it validates the data and as i am not sending any parameters it fails....How can i rectify this? my function for validation is

                             public function validation($min_amount, $max_amount) {
    $validator = new Validation();
    $validator->add('first_name', new PresenceOf([
        'message' => 'First Name cannot be null'
    ]));
    $validator->add('last_name', new PresenceOf([
        'message' => 'Last Name cannot be null'
    ]));
    $validator->add('amount', new PresenceOf([
        'message' => 'Amount cannot be null'
    ]));
    $validator->add('amount', new Between([
        'maximum' => $max_amount,
        'minimum' => $min_amount,
        'message' => "The amount should be between" . $min_amount . " and " . $max_amount,
    ]));
    return $this->validate($validator);
}
edited May '17

Quick and dirty:

if($min_amount !== null && $max_amount !== null) {
    $validator->add('amount', new Between([
        'maximum' => $max_amount,
        'minimum' => $min_amount,
        'message' => "The amount should be between" . $min_amount . " and " . $max_amount,
    ]));
}

I don't know about your app logic, but overriding a method without the same signature (parameters, return type) is a bad practice, even with PHP.

Try renaming validation($min, $max) to myValidation($min, $max) or something, so create/update/save will not call it.