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 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 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
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
      • Exception
      • Locator
      • Paging
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Interface EntityInterface

Describes the methods that any class representing a data storage should comply with.

Namespace: Cake\Datasource

Property Summary

  • $id public @property
    mixed

    Alias for commonly used primary key.

Method Summary

  • clean() public

    Sets the entire entity as clean, which means that it will appear as no fields being modified or added at all. This is an useful call for an initial object hydration

  • extract() public

    Returns an array with the requested fields stored in this entity, indexed by field name

  • extractOriginal() public

    Returns an array with the requested original fields stored in this entity, indexed by field name.

  • extractOriginalChanged() public

    Returns an array with only the original fields stored in this entity, indexed by field name.

  • get() public

    Returns the value of a field by name

  • getDirty() public

    Gets the dirty fields.

  • getError() public

    Returns validation errors of a field

  • getErrors() public

    Returns all validation errors.

  • getHidden() public

    Gets the hidden fields.

  • getOriginal() public

    Returns the original value of a field.

  • getOriginalFields() public

    Returns an array of original fields. Original fields are those that an entity was initialized with.

  • getOriginalValues() public

    Gets all original values of the entity.

  • getPatchable() public

    Patchable configuration for this entity.

  • getSource() public

    Returns the alias of the repository from which this entity came from.

  • getVirtual() public

    Gets the virtual fields on this entity.

  • getVisible() public

    Get the list of visible fields.

  • has() public

    Returns whether this entity contains a field named $field.

    The method will return true even when the field is set to null.

  • hasErrors() public

    Returns whether this entity has errors.

  • hasOriginal() public

    Returns whether a field has an original value

  • hasValue() public

    Checks that a field has a value.

    This method will return true for

    • Non-empty strings
    • Non-empty arrays
    • Any object
    • Integer, even 0
    • Float, even 0.0

    and false in all other cases.

  • isDirty() public

    Checks if the entity is dirty or if a single field of it is dirty.

  • isNew() public

    Returns whether this entity has already been persisted.

  • isOriginalField() public

    Returns whether a field is an original one. Original fields are those that an entity was instantiated with.

  • isPatchable() public

    Checks if a field can be patched

  • patch() public

    Patch the entity with provided values.

  • requireFieldPresence() public

    Enable/disable field presence check when accessing a property.

    If enabled an exception will be thrown when trying to access a non-existent property.

  • set() public

    Sets a field to the specified value.

  • setDirty() public

    Sets the dirty status of a single field.

  • setError() public

    Sets errors for a single field

  • setErrors() public

    Sets error messages to the entity

  • setHidden() public

    Sets hidden fields.

  • setNew() public

    Set the status of this entity.

    Using true means that the entity has not been persisted in the database, false indicates that the entity has been persisted.

  • setPatchable() public

    Stores whether a field value can be changed or set in this entity.

  • setSource() public

    Sets the source alias

  • setVirtual() public

    Sets the virtual fields on this entity.

  • toArray() public

    Returns an array with all the visible fields set in this entity.

    Note hidden fields are not visible, and will not be output by toArray().

  • unset() public

    Removes a field or list of fields from this entity

Method Detail

clean() ¶ public

clean(): void

Sets the entire entity as clean, which means that it will appear as no fields being modified or added at all. This is an useful call for an initial object hydration

Returns
void

extract() ¶ public

extract(array<string> $fields, bool $onlyDirty = false): array<string, mixed>

Returns an array with the requested fields stored in this entity, indexed by field name

Parameters
array<string> $fields

list of fields to be returned

bool $onlyDirty optional

Return the requested field only if it is dirty

Returns
array<string, mixed>

extractOriginal() ¶ public

extractOriginal(array<string> $fields): array<string, mixed>

Returns an array with the requested original fields stored in this entity, indexed by field name.

Parameters
array<string> $fields

List of fields to be returned

Returns
array<string, mixed>

extractOriginalChanged() ¶ public

extractOriginalChanged(array<string> $fields): array<string, mixed>

Returns an array with only the original fields stored in this entity, indexed by field name.

Parameters
array<string> $fields

List of fields to be returned

Returns
array<string, mixed>

get() ¶ public

get(string $field): mixed

Returns the value of a field by name

Parameters
string $field

the name of the field to retrieve

Returns
mixed

getDirty() ¶ public

getDirty(): array<string>

Gets the dirty fields.

Returns
array<string>

getError() ¶ public

getError(string $field): array

Returns validation errors of a field

Parameters
string $field

Field name to get the errors from

Returns
array

getErrors() ¶ public

getErrors(): array

Returns all validation errors.

Returns
array

getHidden() ¶ public

getHidden(): array<string>

Gets the hidden fields.

Returns
array<string>

getOriginal() ¶ public

getOriginal(string $field, bool $allowFallback = true): mixed

Returns the original value of a field.

Parameters
string $field

The name of the field.

bool $allowFallback optional

whether to allow falling back to the current field value if no original exists

Returns
mixed

getOriginalFields() ¶ public

getOriginalFields(): array<string>

Returns an array of original fields. Original fields are those that an entity was initialized with.

Returns
array<string>

getOriginalValues() ¶ public

getOriginalValues(): array<string, mixed>

Gets all original values of the entity.

Returns
array<string, mixed>

getPatchable() ¶ public

getPatchable(): array<string, bool>

Patchable configuration for this entity.

Returns
array<string, bool>

getSource() ¶ public

getSource(): string

Returns the alias of the repository from which this entity came from.

Returns
string

getVirtual() ¶ public

getVirtual(): array<string>

Gets the virtual fields on this entity.

Returns
array<string>

getVisible() ¶ public

getVisible(): array<string>

Get the list of visible fields.

Returns
array<string>

A list of fields that are 'visible' in all representations.

has() ¶ public

has(array<string>|string $field): bool

Returns whether this entity contains a field named $field.

The method will return true even when the field is set to null.

Parameters
array<string>|string $field

The field to check.

Returns
bool

hasErrors() ¶ public

hasErrors(bool $includeNested = true): bool

Returns whether this entity has errors.

Parameters
bool $includeNested optional

true will check nested entities for hasErrors()

Returns
bool

hasOriginal() ¶ public

hasOriginal(string $field): bool

Returns whether a field has an original value

Parameters
string $field
Returns
bool

hasValue() ¶ public

hasValue(string $field): bool

Checks that a field has a value.

This method will return true for

  • Non-empty strings
  • Non-empty arrays
  • Any object
  • Integer, even 0
  • Float, even 0.0

and false in all other cases.

Parameters
string $field

The field to check.

Returns
bool

isDirty() ¶ public

isDirty(string|null $field = null): bool

Checks if the entity is dirty or if a single field of it is dirty.

Parameters
string|null $field optional

The field to check the status for. Null for the whole entity.

Returns
bool

Whether the field was changed or not

isNew() ¶ public

isNew(): bool

Returns whether this entity has already been persisted.

Returns
bool

Whether the entity has been persisted.

isOriginalField() ¶ public

isOriginalField(string $name): bool

Returns whether a field is an original one. Original fields are those that an entity was instantiated with.

Parameters
string $name

Name

Returns
bool

isPatchable() ¶ public

isPatchable(string $field): bool

Checks if a field can be patched

Parameters
string $field

Field name to check

Returns
bool

patch() ¶ public

patch(array<string, mixed> $values, array<string, mixed> $options = []): $this

Patch the entity with provided values.

Parameters
array<string, mixed> $values

Map of fields with their respective values.

array<string, mixed> $options optional

Options to be used for setting the field. Allowed option keys are setter and guard

Returns
$this

requireFieldPresence() ¶ public

requireFieldPresence(bool $value = true): void

Enable/disable field presence check when accessing a property.

If enabled an exception will be thrown when trying to access a non-existent property.

Parameters
bool $value optional

true to enable, false to disable.

Returns
void

set() ¶ public

set(string $field, mixed $value, array<string, mixed> $options = []): $this

Sets a field to the specified value.

Parameters
string $field

The name of field to set.

mixed $value

The value to set to the field.

array<string, mixed> $options optional

Options to be used for setting the field. Allowed option keys are setter and guard

Returns
$this

setDirty() ¶ public

setDirty(string $field, bool $isDirty = true): $this

Sets the dirty status of a single field.

Parameters
string $field

the field to set or check status for

bool $isDirty optional

true means the field was changed, false means it was not changed. Default true.

Returns
$this

setError() ¶ public

setError(string $field, array|string $errors, bool $overwrite = false): $this

Sets errors for a single field

Parameters
string $field

The field to get errors for, or the array of errors to set.

array|string $errors

The errors to be set for $field

bool $overwrite optional

Whether to overwrite pre-existing errors for $field

Returns
$this

setErrors() ¶ public

setErrors(array $errors, bool $overwrite = false): $this

Sets error messages to the entity

Parameters
array $errors

The array of errors to set.

bool $overwrite optional

Whether to overwrite pre-existing errors for $fields

Returns
$this

setHidden() ¶ public

setHidden(array<string> $fields, bool $merge = false): $this

Sets hidden fields.

Parameters
array<string> $fields

An array of fields to hide from array exports.

bool $merge optional

Merge the new fields with the existing. By default false.

Returns
$this

setNew() ¶ public

setNew(bool $new): $this

Set the status of this entity.

Using true means that the entity has not been persisted in the database, false indicates that the entity has been persisted.

Parameters
bool $new

Indicate whether this entity has been persisted.

Returns
$this

setPatchable() ¶ public

setPatchable(array<string>|string $field, bool $set): $this

Stores whether a field value can be changed or set in this entity.

Parameters
array<string>|string $field

single or list of fields to change its accessibility

bool $set

true marks the field as patchable, false will mark it as protected.

Returns
$this

setSource() ¶ public

setSource(string $alias): $this

Sets the source alias

Parameters
string $alias

the alias of the repository

Returns
$this

setVirtual() ¶ public

setVirtual(array<string> $fields, bool $merge = false): $this

Sets the virtual fields on this entity.

Parameters
array<string> $fields

An array of fields to treat as virtual.

bool $merge optional

Merge the new fields with the existing. By default false.

Returns
$this

toArray() ¶ public

toArray(): array<string, mixed>

Returns an array with all the visible fields set in this entity.

Note hidden fields are not visible, and will not be output by toArray().

Returns
array<string, mixed>

unset() ¶ public

unset(array<string>|string $field): $this

Removes a field or list of fields from this entity

Parameters
array<string>|string $field

The field to unset.

Returns
$this

Property Detail

$id ¶ public @property

Alias for commonly used primary key.

Type
mixed
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