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 use validation in Model

I was setting a custom validation for my User model:

public function validation()
{
    $this->validate(new \Phalcon\Mvc\Model\Validator\PresenceOf([
            'field' => 'nick',
            'message' => 'stupid validation'
    ]));

    return !$this->validationHasFailed();
}

It throws the same default message everytime (nick is required). Shouldn't be replaced with the new message? It worked the first time I did it (I thought).

edited Nov '14

Maybe you have same validator in your form, and the default message comes from there. :/



33.8k
edited Nov '14

Nope, I only have the model's validator as a validator in the whole app, nothing more.

EDIT: I've investigated more and did a manually $user->validation(). And guess what? Prints the personalized messages.

So, the problem is that $user->create/save/update() isn't calling the validation. Why?