CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.6 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.6
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeValidationRule
  • CakeValidationSet

Class CakeValidationSet

CakeValidationSet object. Holds all validation rules for a field and exposes methods to dynamically add or remove validation rules

CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable
Package: Cake\Model\Validator
Link: http://book.cakephp.org/2.0/en/data-validation.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Model/Validator/CakeValidationSet.php

Properties summary

  • $_methods protected
    array
    List of methods available for validation
  • $_rules protected
    array
    Holds the CakeValidationRule objects
  • $_validationDomain protected
    string
    I18n domain for validation messages.
  • $field public
    string
    Holds the fieldname
  • $isStopped public
    boolean
    Whether the validation is stopped
  • $ruleSet public
    array
    Holds the original ruleSet

Method Summary

  • __construct() public
    Constructor
  • _processValidationResponse() protected
    Fetches the correct error message for a failed validation
  • _translateArgs() protected
    Applies translations to validator arguments.
  • count() public
    Returns the number of rules in this set
  • getIterator() public
    Returns an iterator for each of the rules to be applied
  • getRule() public
    Gets a rule for a given name if exists
  • getRules() public
    Returns all rules for this validation set
  • offsetExists() public
    Returns whether an index exists in the rule set
  • offsetGet() public
    Returns a rule object by its index
  • offsetSet() public
    Sets or replace a validation rule.
  • offsetUnset() public
    Unsets a validation rule
  • removeRule() public
    Removes a validation rule from the set
  • reset() public
    Resets internal state for all validation rules in this set
  • setMethods() public
    Sets the list of methods to use for validation
  • setRule() public
    Sets a CakeValidationRule $rule with a $name
  • setRules() public
    Sets the rules for a given field
  • setValidationDomain() public
    Sets the I18n domain for validation messages.
  • validate() public

    Runs all validation rules in this set and returns a list of validation errors

Method Detail

__construct() public ¶

__construct( string $fieldName , array $ruleSet )

Constructor

Parameters
string $fieldName
The fieldname.
array $ruleSet
Rules set.

_processValidationResponse() protected ¶

_processValidationResponse( string $name , CakeValidationRule $rule )

Fetches the correct error message for a failed validation

Parameters
string $name
the name of the rule as it was configured
CakeValidationRule $rule
the object containing validation information
Returns
string

_translateArgs() protected ¶

_translateArgs( array $args )

Applies translations to validator arguments.

Parameters
array $args
The args to translate
Returns
array
Translated args.

count() public ¶

count( )

Returns the number of rules in this set

Returns
integer
Implementation of
Countable::count()

getIterator() public ¶

getIterator( )

Returns an iterator for each of the rules to be applied

Returns
ArrayIterator
Implementation of
IteratorAggregate::getIterator()

getRule() public ¶

getRule( string $name )

Gets a rule for a given name if exists

Parameters
string $name
Field name.
Returns
CakeValidationRule

getRules() public ¶

getRules( )

Returns all rules for this validation set

Returns
array

offsetExists() public ¶

offsetExists( string $index )

Returns whether an index exists in the rule set

Parameters
string $index
name of the rule
Returns
boolean
Implementation of
ArrayAccess::offsetExists()

offsetGet() public ¶

offsetGet( string $index )

Returns a rule object by its index

Parameters
string $index
name of the rule
Returns
CakeValidationRule
Implementation of
ArrayAccess::offsetGet()

offsetSet() public ¶

offsetSet( string $index , CakeValidationRule|array $rule )

Sets or replace a validation rule.

This is a wrapper for ArrayAccess. Use setRule() directly for chainable access.

Parameters
string $index
Name of the rule.
CakeValidationRule|array $rule
Rule to add to $index.
See
http://www.php.net/manual/en/arrayobject.offsetset.php
Implementation of
ArrayAccess::offsetSet()

offsetUnset() public ¶

offsetUnset( string $index )

Unsets a validation rule

Parameters
string $index
name of the rule
Implementation of
ArrayAccess::offsetUnset()

removeRule() public ¶

removeRule( string $name )

Removes a validation rule from the set

Example:

$set
        ->removeRule('required')
        ->removeRule('inRange')
Parameters
string $name
The name under which the rule should be unset
Returns

$this

reset() public ¶

reset( )

Resets internal state for all validation rules in this set

setMethods() public ¶

setMethods( array $methods )

Sets the list of methods to use for validation

Parameters
array $methods
$methods Methods list

setRule() public ¶

setRule( string $name , CakeValidationRule|array $rule )

Sets a CakeValidationRule $rule with a $name

Example:

$set
        ->setRule('required', array('rule' => 'notEmpty', 'required' => true))
        ->setRule('between', array('rule' => array('lengthBetween', 4, 10))
Parameters
string $name
The name under which the rule should be set
CakeValidationRule|array $rule
The validation rule to be set
Returns

$this

setRules() public ¶

setRules( array $rules = array() , boolean $mergeVars = true )

Sets the rules for a given field

Example:

$set->setRules(array(
        'required' => array('rule' => 'notEmpty', 'required' => true),
        'inRange' => array('rule' => array('between', 4, 10)
        ));
Parameters
array $rules optional array()
The rules to be set
boolean $mergeVars optional true
[optional] If true, merges vars instead of replace. Defaults to true.
Returns

$this

setValidationDomain() public ¶

setValidationDomain( string $validationDomain )

Sets the I18n domain for validation messages.

Parameters
string $validationDomain
The validation domain to be used.

validate() public ¶

validate( array $data , boolean $isUpdate = false )

Runs all validation rules in this set and returns a list of validation errors

Parameters
array $data
Data array
boolean $isUpdate optional false
Is record being updated or created
Returns
array
list of validation errors for this field

Properties detail

$_methods ¶

protected array

List of methods available for validation

array()

$_rules ¶

protected array

Holds the CakeValidationRule objects

array()

$_validationDomain ¶

protected string

I18n domain for validation messages.

null

$field ¶

public string

Holds the fieldname

null

$isStopped ¶

public boolean

Whether the validation is stopped

false

$ruleSet ¶

public array

Holds the original ruleSet

array()
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs