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
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.1 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 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

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class ValidationSet

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

Namespace: Cake\Validation

Property Summary

  • $_allowEmpty protected
    callable|string|bool

    Denotes if a field is allowed to be empty

  • $_rules protected
    array<Cake\Validation\ValidationRule>

    Holds the ValidationRule objects

  • $_validatePresent protected
    callable|string|bool

    Denotes whether the fieldname key must be present in data array

Method Summary

  • add() public

    Sets a ValidationRule $rule with a $name

  • allowEmpty() public

    Sets whether a field value is allowed to be empty.

  • count() public

    Returns the number of rules in this set

  • getIterator() public

    Returns an iterator for each of the rules to be applied

  • isEmptyAllowed() public

    Returns whether a field can be left empty.

  • isPresenceRequired() public

    Returns whether a field can be left out.

  • 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

  • remove() public

    Removes a validation rule from the set

  • requirePresence() public

    Sets whether a field is required to be present in data array.

  • rule() public

    Gets a rule for a given name if exists

  • rules() public

    Returns all rules for this validation set

Method Detail

add() ¶ public

add(string $name, Cake\Validation\ValidationRule|array $rule): $this

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
$this

allowEmpty() ¶ public

allowEmpty(callable|string|bool $allowEmpty): $this

Sets whether a field value is allowed to be empty.

Parameters
callable|string|bool $allowEmpty

Valid values are true, false, 'create', 'update' or a callable.

Returns
$this

count() ¶ public

count(): int

Returns the number of rules in this set

Returns
int

getIterator() ¶ public

getIterator(): Traversable<string, \Cake\Validation\ValidationRule>

Returns an iterator for each of the rules to be applied

Returns
Traversable<string, \Cake\Validation\ValidationRule>

isEmptyAllowed() ¶ public

isEmptyAllowed(): callable|string|bool

Returns whether a field can be left empty.

Returns
callable|string|bool

isPresenceRequired() ¶ public

isPresenceRequired(): callable|string|bool

Returns whether a field can be left out.

Returns
callable|string|bool

offsetExists() ¶ public

offsetExists(string $index): bool

Returns whether an index exists in the rule set

Parameters
string $index

name of the rule

Returns
bool

offsetGet() ¶ public

offsetGet(string $index): Cake\Validation\ValidationRule

Returns a rule object by its index

Parameters
string $index

name of the rule

Returns
Cake\Validation\ValidationRule

offsetSet() ¶ public

offsetSet(string $offset, Cake\Validation\ValidationRule|array $value): void

Sets or replace a validation rule

Parameters
string $offset

name of the rule

Cake\Validation\ValidationRule|array $value

Rule to add to $index

Returns
void

offsetUnset() ¶ public

offsetUnset(string $index): void

Unsets a validation rule

Parameters
string $index

name of the rule

Returns
void

remove() ¶ public

remove(string $name): $this

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
$this

requirePresence() ¶ public

requirePresence(callable|string|bool $validatePresent): $this

Sets whether a field is required to be present in data array.

Parameters
callable|string|bool $validatePresent

Valid values are true, false, 'create', 'update' or a callable.

Returns
$this

rule() ¶ public

rule(string $name): Cake\Validation\ValidationRule|null

Gets a rule for a given name if exists

Parameters
string $name

The name under which the rule is set.

Returns
Cake\Validation\ValidationRule|null

rules() ¶ public

rules(): array<Cake\Validation\ValidationRule>

Returns all rules for this validation set

Returns
array<Cake\Validation\ValidationRule>

Property Detail

$_allowEmpty ¶ protected

Denotes if a field is allowed to be empty

Type
callable|string|bool

$_rules ¶ protected

Holds the ValidationRule objects

Type
array<Cake\Validation\ValidationRule>

$_validatePresent ¶ protected

Denotes whether the fieldname key must be present in data array

Type
callable|string|bool
OpenHub
Pingping
Linode
  • 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
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs