Class CakeValidationRule
CakeValidationRule object. Represents a validation method, error message and rules for applying such method to a field.
Link: https://book.cakephp.org/2.0/en/data-validation.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Model/Validator/CakeValidationRule.php
Properties summary
-
$_passedOptions
protectedHolds passed in optionsarray
-
$_recordExists
protectedHolds whether the record being validated exists in datasource or notboolean
-
$_rule
protectedValidation methodmixed
-
$_ruleParams
protectedValidation method argumentsarray
-
$_valid
protectedWhether the field passed this validation rulemixed
-
$allowEmpty
publicThe 'allowEmpty' keyboolean
-
$last
publicThe 'last' keyboolean
-
$message
publicThe 'message' keystring
-
$on
publicThe 'on' keystring
-
$required
publicThe 'required' keymixed
-
$rule
publicThe 'rule' keymixed
Method Summary
- __construct() publicConstructor
- _addValidatorProps() protectedSets the rule properties from the rule entry in validate
- _getPropertiesArray() protectedGets an array with the rule properties
- _parseRule() protectedParses the rule and sets the rule and ruleParams
- checkEmpty() publicChecks if the allowEmpty key applies
- checkRequired() publicChecks whether the field failed the
field should be present
validation - getOptions() publicReturns passed options for this rule
- getValidationResult() publicGets the validation error message
- isEmptyAllowed() publicReturns whether the field can be left blank according to this rule
- isLast() public
Returns whether this rule should break validation process for associated field after it fails
- isRequired() publicChecks if the field is required according to the
required
property - isUpdate() public
Sets the recordExists configuration value for this rule, ir refers to whether the model record it is validating exists exists in the collection or not (create or update operation)
- isValid() publicChecks if the rule is valid
- process() publicDispatches the validation rule to the given validator method
- reset() public
Resets internal state for this rule, by default it will become valid and it will set isUpdate() to false
- skip() publicChecks if the validation rule should be skipped
Method Detail
__construct()source public
__construct( array $validator array() )
Constructor
Parameters
- array
$validator
optional array() - [optional] The validator properties
_addValidatorProps()source protected
_addValidatorProps( array $validator array() )
Sets the rule properties from the rule entry in validate
Parameters
- array
$validator
optional array() - [optional]
_getPropertiesArray()source protected
_getPropertiesArray( )
Gets an array with the rule properties
Returns
array_parseRule()source protected
_parseRule( string $field , array $data )
Parses the rule and sets the rule and ruleParams
Parameters
- string
$field
- Field name
- array
$data
- $data Data array
checkEmpty()source public
checkEmpty( string $field , array $data )
Checks if the allowEmpty key applies
Parameters
- string
$field
- Field name
- array
$data
- $data data to check rule against
Returns
booleancheckRequired()source public
checkRequired( string $field , array $data )
Checks whether the field failed the field should be present
validation
Parameters
- string
$field
- Field name
- array
$data
- $data Data to check rule against
Returns
booleangetOptions()source public
getOptions( string|integer $key )
Returns passed options for this rule
Parameters
- string|integer
$key
- Array index
Returns
array|nullgetValidationResult()source public
getValidationResult( )
Gets the validation error message
Returns
stringisEmptyAllowed()source public
isEmptyAllowed( )
Returns whether the field can be left blank according to this rule
Returns
booleanisLast()source public
isLast( )
Returns whether this rule should break validation process for associated field after it fails
Returns
booleanisRequired()source public
isRequired( )
Checks if the field is required according to the required
property
Returns
booleanisUpdate()source public
isUpdate( boolean $exists null )
Sets the recordExists configuration value for this rule, ir refers to whether the model record it is validating exists exists in the collection or not (create or update operation)
If called with no parameters it will return whether this rule is configured for update operations or not.
Parameters
- boolean
$exists
optional null - Boolean to indicate if records exists
Returns
booleanprocess()source public
process( string $field , array $data , array $methods )
Dispatches the validation rule to the given validator method
Parameters
- string
$field
- Field name
- array
$data
- $data Data array
- array
$methods
- $methods Methods list
Returns
booleanTrue if the rule could be dispatched, false otherwise
reset()source public
reset( )
Resets internal state for this rule, by default it will become valid and it will set isUpdate() to false
skip()source public
skip( )
Checks if the validation rule should be skipped
Returns
booleanTrue if the ValidationRule can be skipped
Properties detail
$_recordExistssource
protected boolean
Holds whether the record being validated exists in datasource or not
false
© 2005–2017 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/2.10/class-CakeValidationRule.html