BuscarTabla de ContenidosTema anteriorPróximo temaEsta página |
Validation¶PhalconValidation is an independent validation component to validate an arbitrary set of data. This component can be used to implement validation rules that does not belong to a model or collection. The following example shows its basic usage: use Phalcon\Validation\Validator\PresenceOf,
Phalcon\Validation\Validator\Email;
$validation = new Phalcon\Validation();
$validation->add('name', new PresenceOf(
'message' => 'The name is required'
));
$validation->add('email', new PresenceOf(
'message' => 'The e-mail is required'
));
$validation->add('email', new Email(
'message' => 'The e-mail is not valid'
));
$messages = $validation->validate($_POST);
if (count($messages)) {
foreach ($messages as $message) {
echo $message, '<br>;
}
}
Validators¶Phalcon exposes a set of built-in validators for this component:
Additional validators can be created by the developer. The following class explains how to create a validator for this component:
|