Abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
This is a base class for Phalcon\Mvc\Model validators
This class is only for backward compatibility reasons to use with Phalcon\Mvc\Collection.
Otherwise please use the validators provided by Phalcon\Validation.
Methods
public __construct (array $options)
Phalcon\Mvc\Model\Validator constructor
protected appendMessage (string $message, [string |
array $field], [string $type]) |
Appends a message to the validator
public getMessages ()
Returns messages generated by the validator
public array getOptions ()
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue])
Returns an option
public isSetOption (mixed $option)
Check whether an option has been defined in the validator options
abstract public validate (Phalcon\Mvc\EntityInterface $record) inherited from Phalcon\Mvc\Model\ValidatorInterface
…
Class Phalcon\Mvc\Model\Validator\Email
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Allows to validate if email fields has correct values
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\Email as EmailValidator;
class Subscriptors extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new EmailValidator(
[
"field" => "electronic_mail",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Exclusionin
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Phalcon\Mvc\Model\Validator\ExclusionIn
Check if a value is not included into a list of values
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\ExclusionIn as ExclusionInValidator;
class Subscriptors extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new ExclusionInValidator(
[
"field" => "status",
"domain" => ["A", "I"],
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Inclusionin
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Phalcon\Mvc\Model\Validator\InclusionIn
Check if a value is included into a list of values
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\InclusionIn as InclusionInValidator;
class Subscriptors extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new InclusionInValidator(
[
"field" => "status",
"domain" => ["A", "I"],
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Ip
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Phalcon\Mvc\Model\Validator\IP
Validates that a value is ipv4 address in valid range
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\Ip;
class Data extends \Phalcon\Mvc\Collection
{
public function validation()
{
// Any pubic IP
$this->validate(
new IP(
[
"field" => "server_ip",
"version" => IP::VERSION_4 | IP::VERSION_6, // v6 and v4. The same if not specified
"allowReserved" => false, // False if not specified. Ignored for v6
"allowPrivate" => false, // False if not specified
"message" => "IP address has to be correct",
]
)
);
// Any public v4 address
$this->validate(
new IP(
[
"field" => "ip_4",
"version" => IP::VERSION_4,
"message" => "IP address has to be correct",
]
)
);
// Any v6 address
$this->validate(
new IP(
[
"field" => "ip6",
"version" => IP::VERSION_6,
"allowPrivate" => true,
"message" => "IP address has to be correct",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Constants
integer VERSION_4
integer VERSION_6
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Numericality
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Allows to validate if a field has a valid numeric format
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\Numericality as NumericalityValidator;
class Products extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new NumericalityValidator(
[
"field" => "price",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\PresenceOf
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Allows to validate if a filed have a value different of null and empty string (“”)
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\PresenceOf;
class Subscriptors extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new PresenceOf(
[
"field" => "name",
"message" => "The name is required",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Regex
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Allows validate if the value of a field matches a regular expression
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\Regex as RegexValidator;
class Subscriptors extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new RegexValidator(
[
"field" => "created_at",
"pattern" => "/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])/",
]
)
);
if ($this->validationHasFailed() == true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\StringLength
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Simply validates specified string length constraints
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\StringLength as StringLengthValidator;
class Subscriptors extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new StringLengthValidator(
[
"field" => "name_last",
"max" => 50,
"min" => 2,
"messageMaximum" => "We don't like really long names",
"messageMinimum" => "We want more than just their initials",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Uniqueness
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Validates that a field or a combination of a set of fields are not
present more than once in the existing records of the related table
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Collection;
use Phalcon\Mvc\Model\Validator\Uniqueness;
class Subscriptors extends Collection
{
public function validation()
{
$this->validate(
new Uniqueness(
[
"field" => "email",
"message" => "Value of field 'email' is already present in another record",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Class Phalcon\Mvc\Model\Validator\Url
extends abstract class Phalcon\Mvc\Model\Validator
implements Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Allows to validate if a field has a url format
This validator is only for use with Phalcon\Mvc\Collection. If you are using
Phalcon\Mvc\Model, please use the validators provided by Phalcon\Validation.
<?php
use Phalcon\Mvc\Model\Validator\Url as UrlValidator;
class Posts extends \Phalcon\Mvc\Collection
{
public function validation()
{
$this->validate(
new UrlValidator(
[
"field" => "source_url",
]
)
);
if ($this->validationHasFailed() === true) {
return false;
}
}
}
Methods
public validate (Phalcon\Mvc\EntityInterface $record)
Executes the validator
public __construct (array $options) inherited from Phalcon\Mvc\Model\Validator
Phalcon\Mvc\Model\Validator constructor
Appends a message to the validator
public getMessages () inherited from Phalcon\Mvc\Model\Validator
Returns messages generated by the validator
public array getOptions () inherited from Phalcon\Mvc\Model\Validator
Returns all the options from the validator
public getOption (mixed $option, [mixed $defaultValue]) inherited from Phalcon\Mvc\Model\Validator
Returns an option
public isSetOption (mixed $option) inherited from Phalcon\Mvc\Model\Validator
Check whether an option has been defined in the validator options
Interface Phalcon\Mvc\Model\ValidatorInterface
Source on GitHub
Methods
abstract public getMessages ()
…
abstract public validate (Phalcon\Mvc\EntityInterface $record)
…