Model Validation
Phalcon\Mvc\Model provides several events to validate data and implement business rules. The special event allows us to call built-in validators over the record. Phalcon exposes a few built-in validators that can be used at this stage of validation.
The following example shows how to use it:
The idea of creating validators is make them reusable between several models. A validator can also be as simple as:
Each message is an instance of and the set of messages generated can be retrieved with the getMessages()
method. Each message provides extended information like the field name that generated the message or the message type:
Phalcon\Mvc\Model can generate the following types of validation messages:
Another type of events are available when the data validation process finds any inconsistency:
Operation | Name | Explanation |
---|---|---|
Insert or Update | notSaved | Triggered when the INSERT or UPDATE operation fails for any reason |
Insert, Delete or Update | Triggered when any data manipulation operation fails |