I am trying to validate data integrity via the special validation event. My Phalcon\Mvc\Collection model implements the validation() method with some Phalcon\Mvc\Model\Validator validators. In my controller, I save() that model. If the save operation fails, I try to output the error messages via the getMessages() method of the model. In other words, I follow the examples supplied in the documentation http://docs.phalconphp.com/en/latest/reference/odm.html
However, I get an error that the getMessages() method does not exist. My Phalcon version is 0.7.0. I checked the API http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Collection.html, and it does not show a getMessages() method. I also ran a reflection test on the Phalcon\Mvc\Collection class, and that observation was confirmed.
The documentation also states that we can implement our own validators using Phalcon\Mvc\Collection\Validator. However, it appears that this class does not exist.
So, my questions are:
- How do I show the error messages that are a result of a validation?
- How do I create custom validators?
- Is Phalcon\Mvc\Model\Validator\Uniqueness validator NOSQL compatible?
Thank you for your time.
You’re right the getMessages() method was missing in the implementation. For now you can add it to your model while it’s officially added to the C class:
1- How do I show the error messages that are a result of a validation? Check above
2- How do I create custom validators?
A validator is a class that inherits from “Phalcon\Mvc\Model\Validator” and implements “Phalcon\Mvc\Model\ValidatorInterface”:
If you don’t want to reuse the validator you can simply add a validation rule to the model:
3- Is Phalcon\Mvc\Model\Validator\Uniqueness validator NOSQL compatible?
This validator is only compatible with SQL models, however, you can create a validator to work with NoSQL collections this way: