Class ValidationSet
ValidationSet object. Holds all validation rules for a field and exposes methods to dynamically add or remove validation rules
Properties summary
- $_allowEmpty protected
bool|string|callableDenotes if a field is allowed to be empty
- $_rules protected
\Cake\Validation\ValidationRule[]Holds the ValidationRule objects
- $_validatePresent protected
bool|string|callableDenotes whether the fieldname key must be present in data array
Method Summary
Method Detail
add() public
add(string $name, mixed $rule)
Sets a ValidationRule $rule with a $name
Example:
$set
->add('notBlank', ['rule' => 'notBlank'])
->add('inRange', ['rule' => ['between', 4, 10]) Parameters
-
string$name The name under which the rule should be set
-
\Cake\Validation\ValidationRule|array$rule The validation rule to be set
Returns
$thisallowEmpty() public
allowEmpty(mixed $allowEmpty)
Sets whether a field value is allowed to be empty.
Parameters
-
bool|string|callable$allowEmpty Valid values are true, false, 'create', 'update' or a callable.
Returns
$thiscount() public
count()
Returns the number of rules in this set
Returns
intgetIterator() public
getIterator()
Returns an iterator for each of the rules to be applied
Returns
\Cake\Validation\ValidationRule[]isEmptyAllowed() public
isEmptyAllowed()
Returns whether or not a field can be left empty.
Returns
bool|string|callableisPresenceRequired() public
isPresenceRequired()
Returns whether or not a field can be left out.
Returns
bool|string|callableoffsetExists() public
offsetExists(mixed $index)
Returns whether an index exists in the rule set
Parameters
-
string$index name of the rule
Returns
booloffsetGet() public
offsetGet(mixed $index)
Returns a rule object by its index
Parameters
-
string$index name of the rule
Returns
\Cake\Validation\ValidationRuleoffsetSet() public
offsetSet(mixed $index, mixed $rule)
Sets or replace a validation rule
Parameters
-
string$index name of the rule
-
\Cake\Validation\ValidationRule|array$rule Rule to add to $index
offsetUnset() public
offsetUnset(mixed $index)
Unsets a validation rule
Parameters
-
string$index name of the rule
remove() public
remove(string $name)
Removes a validation rule from the set
Example:
$set
->remove('notBlank')
->remove('inRange') Parameters
-
string$name The name under which the rule should be unset
Returns
$thisrequirePresence() public
requirePresence(mixed $validatePresent)
Sets whether a field is required to be present in data array.
Parameters
-
bool|string|callable$validatePresent Valid values are true, false, 'create', 'update' or a callable.
Returns
$thisrule() public
rule(string $name)
Gets a rule for a given name if exists
Parameters
-
string$name The name under which the rule is set.
Returns
\Cake\Validation\ValidationRule|nullrules() public
rules()
Returns all rules for this validation set
Returns
\Cake\Validation\ValidationRule[]Property Detail
$_allowEmpty protected
Denotes if a field is allowed to be empty
Type
bool|string|callable$_rules protected
Holds the ValidationRule objects
Type
\Cake\Validation\ValidationRule[]$_validatePresent protected
Denotes whether the fieldname key must be present in data array
Type
bool|string|callable
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Validation.ValidationSet.html