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 http://docs.phalconphp.com/en/latest/api/Phalcon%5Validation.html versus http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5Validator.html

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



84.5k

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.