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 3.3 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.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
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
      • Exception
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Interface RepositoryInterface

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

Namespace: Cake\Datasource

Method Summary

  • alias() public

    Returns the table alias or sets a new one

  • delete() public

    Delete a single entity.

  • deleteAll() public

    Deletes all records matching the provided conditions.

  • exists() public

    Returns true if there is any record in this repository matching the specified conditions.

  • find() public

    Creates a new Query for this repository and applies some defaults based on the type of search that was selected.

  • get() public

    Returns a single record after finding it by its primary key, if no record is found this method throws an exception.

  • hasField() public

    Test to see if a Repository has a specific field/column.

  • newEntities() public

    Create a list of entities + associated entities from an array.

  • newEntity() public

    Create a new entity + associated entities from an array.

  • patchEntities() public

    Merges each of the elements passed in $data into the entities found in $entities respecting the accessible fields configured on the entities. Merging is done by matching the primary key in each of the elements in $data and $entities.

  • patchEntity() public

    Merges the passed $data into $entity respecting the accessible fields configured on the entity. Returns the same entity after being altered.

  • query() public

    Creates a new Query instance for this repository

  • save() public

    Persists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error.

  • updateAll() public

    Update all matching records.

Method Detail

alias() ¶ public

alias(string|null $alias = null): string

Returns the table alias or sets a new one

Parameters
string|null $alias optional

the new table alias

Returns
string

delete() ¶ public

delete(Cake\Datasource\EntityInterface $entity, array|ArrayAccess $options = []): bool

Delete a single entity.

Deletes an entity and possibly related associations from the database based on the 'dependent' option used when defining the association.

Parameters
Cake\Datasource\EntityInterface $entity

The entity to remove.

array|ArrayAccess $options optional

The options for the delete.

Returns
bool

deleteAll() ¶ public

deleteAll(mixed $conditions): int

Deletes all records matching the provided conditions.

This method will not trigger beforeDelete/afterDelete events. If you need those first load a collection of records and delete them.

This method will not execute on associations' cascade attribute. You should use database foreign keys + ON CASCADE rules if you need cascading deletes combined with this method.

Parameters
mixed $conditions

Conditions to be used, accepts anything Query::where() can take.

Returns
int
See Also
\Cake\Datasource\RepositoryInterface::delete()

exists() ¶ public

exists(array|ArrayAccess $conditions): bool

Returns true if there is any record in this repository matching the specified conditions.

Parameters
array|ArrayAccess $conditions

list of conditions to pass to the query

Returns
bool

find() ¶ public

find(string $type = 'all', array|ArrayAccess $options = []): Cake\ORM\Query

Creates a new Query for this repository and applies some defaults based on the type of search that was selected.

Model.beforeFind event

Each find() will trigger a Model.beforeFind event for all attached listeners. Any listener can set a valid result set using $query

Parameters
string $type optional

the type of query to perform

array|ArrayAccess $options optional

An array that will be passed to Query::applyOptions()

Returns
Cake\ORM\Query

get() ¶ public

get(mixed $primaryKey, array|ArrayAccess $options = []): Cake\Datasource\EntityInterface

Returns a single record after finding it by its primary key, if no record is found this method throws an exception.

Example:

$id = 10;
$article = $articles->get($id);

$article = $articles->get($id, ['contain' => ['Comments]]);
Parameters
mixed $primaryKey

primary key value to find

array|ArrayAccess $options optional

options accepted by Table::find()

Returns
Cake\Datasource\EntityInterface
Throws
Cake\Datasource\Exception\RecordNotFoundException
if the record with such id could not be found
See Also
\Cake\Datasource\RepositoryInterface::find()

hasField() ¶ public

hasField(string $field): bool

Test to see if a Repository has a specific field/column.

Parameters
string $field

The field to check for.

Returns
bool

newEntities() ¶ public

newEntities(array $data, array $options = []): array

Create a list of entities + associated entities from an array.

This is most useful when hydrating request data back into entities. For example, in your controller code:

$articles = $this->Articles->newEntities($this->request->data());

The hydrated entities can then be iterated and saved.

Parameters
array $data

The data to build an entity with.

array $options optional

A list of options for the objects hydration.

Returns
array

newEntity() ¶ public

newEntity(array|null $data = null, array $options = []): Cake\Datasource\EntityInterface

Create a new entity + associated entities from an array.

This is most useful when hydrating request data back into entities. For example, in your controller code:

$article = $this->Articles->newEntity($this->request->data());

The hydrated entity will correctly do an insert/update based on the primary key data existing in the database when the entity is saved. Until the entity is saved, it will be a detached record.

Parameters
array|null $data optional

The data to build an entity with.

array $options optional

A list of options for the object hydration.

Returns
Cake\Datasource\EntityInterface

patchEntities() ¶ public

patchEntities(array|Traversable $entities, array $data, array $options = []): array

Merges each of the elements passed in $data into the entities found in $entities respecting the accessible fields configured on the entities. Merging is done by matching the primary key in each of the elements in $data and $entities.

This is most useful when editing a list of existing entities using request data:

$article = $this->Articles->patchEntities($articles, $this->request->data());
Parameters
array|Traversable $entities

the entities that will get the data merged in

array $data

list of arrays to be merged into the entities

array $options optional

A list of options for the objects hydration.

Returns
array

patchEntity() ¶ public

patchEntity(Cake\Datasource\EntityInterface $entity, array $data, array $options = []): Cake\Datasource\EntityInterface

Merges the passed $data into $entity respecting the accessible fields configured on the entity. Returns the same entity after being altered.

This is most useful when editing an existing entity using request data:

$article = $this->Articles->patchEntity($article, $this->request->data());
Parameters
Cake\Datasource\EntityInterface $entity

the entity that will get the data merged in

array $data

key value list of fields to be merged into the entity

array $options optional

A list of options for the object hydration.

Returns
Cake\Datasource\EntityInterface

query() ¶ public

query(): Cake\ORM\Query

Creates a new Query instance for this repository

Returns
Cake\ORM\Query

save() ¶ public

save(Cake\Datasource\EntityInterface $entity, array|ArrayAccess $options = []): Cake\Datasource\EntityInterface|bool

Persists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error.

Parameters
Cake\Datasource\EntityInterface $entity

the entity to be saved

array|ArrayAccess $options optional

The options to use when saving.

Returns
Cake\Datasource\EntityInterface|bool

updateAll() ¶ public

updateAll(string|array|callable|Cake\Database\Expression\QueryExpression $fields, mixed $conditions): int

Update all matching records.

Sets the $fields to the provided values based on $conditions. This method will not trigger beforeSave/afterSave events. If you need those first load a collection of records and update them.

Parameters
string|array|callable|Cake\Database\Expression\QueryExpression $fields

A hash of field => new value.

mixed $conditions

Conditions to be used, accepts anything Query::where() can take.

Returns
int
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