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

Models validation cancelOnFail

Why is that when I use models validation, i can't use the cancelOnFail function?

$this->validate(new PresenceOf(
        array(
            "field"  => "firstname",
            'message' => 'Du skal skrive dit fornavn.',
            'cancelOnFail' => true
        )
    ));

I dont get any errors, it just doesn't work.. Is there any way I can make it work?

This feature is not implemented in model validations only in Phalcon\Validation

Okay, is there any other way of doing this?

Becuse uniqueness dosent work in Phalcon/Validation, only in models..

You can use a Model::count() in the validation method.

public function validation()
{
    if (SomeModel::countByField($this->field)) {       
       return false;
    }

    // other validations
    return true;
}

Is it a bug, that uniqueness can't be found when validation outside model? Because when I do, it can't find the class?