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

What is the difference between the Model Validator and Validation Class?

I can do this in my model:

use Phalcon\Mvc\Model\Validator; $this->validate(new Validator\Email([ 'field' => 'email', 'message' => 'Sorry, your email is invalid.' ]));

But Why cant do this? $this->validate->appendMessage('test');

1: How would I do a custom validation and add it into there? For example if (true) { $this->validate->appendMessage('You cant do that!'); $this->validate->setFailure? }

2: What is the "field" value coming from? Is it the model::$value?

3: Then whats the difference with this https://docs.phalcon.io/en/latest/api/Phalcon_Validation.html versus https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Validator.html

Does the model validation just have more features only for the models?



98.9k

Phalcon\Mvc\Model\Validator is intended to perform validations on models.

Phalcon\Validation is intended to perform validations on arbitrary data that not necessarily belongs or will be stored to/from a model. For example a form that process some data that will be used to send an email.