Fr3nch13/CakePHP Utilities

TableRegistry
in package

Provides a registry/factory for Table objects.

This registry allows you to centralize the configuration for tables their connections and other meta-data.

Configuring instances

You may need to configure your table objects. Using the TableLocator you can centralize configuration. Any configuration set before instances are created will be used when creating instances. If you modify configuration after an instance is made, the instances will not be updated.

TableRegistry::getTableLocator()->setConfig('Users', ['table' => 'my_users']);

// Prior to 3.6.0
TableRegistry::config('Users', ['table' => 'my_users']);

Configuration data is stored per alias if you use the same table with multiple aliases you will need to set configuration multiple times.

Getting instances

You can fetch instances out of the registry through TableLocator::get(). One instance is stored per alias. Once an alias is populated the same instance will always be returned. This reduces the ORM memory cost and helps make cyclic references easier to solve.

$table = TableRegistry::getTableLocator()->get('Users', $config);

// Prior to 3.6.0
$table = TableRegistry::get('Users', $config);

Table of Contents

Methods

clear()  : void
Clears the registry of configuration and instances.
exists()  : bool
Check to see if an instance exists in the registry.
get()  : Table
Get a table instance from the registry.
getTableLocator()  : LocatorInterface
Returns a singleton instance of LocatorInterface implementation.
remove()  : void
Removes an instance from the registry.
set()  : Table
Set an instance.
setTableLocator()  : void
Sets singleton instance of LocatorInterface implementation.

Methods

clear()

Clears the registry of configuration and instances.

public static clear() : void

Use instead. Will be removed in 5.0

exists()

Check to see if an instance exists in the registry.

public static exists(string $alias) : bool

Use instead. Will be removed in 5.0

Parameters
$alias : string

The alias to check for.

Return values
bool

get()

Get a table instance from the registry.

public static get(string $alias[, array<string, mixed> $options = [] ]) : Table

Use instead. Will be removed in 5.0.

See options specification in .

Parameters
$alias : string

The alias name you want to get.

$options : array<string, mixed> = []

The options you want to build the table with.

Return values
Table

remove()

Removes an instance from the registry.

public static remove(string $alias) : void

Use instead. Will be removed in 5.0

Parameters
$alias : string

The alias to remove.

set()

Set an instance.

public static set(string $alias, Table $object) : Table

Use instead. Will be removed in 5.0

Parameters
$alias : string

The alias to set.

$object : Table

The table to set.

Return values
Table

setTableLocator()

Sets singleton instance of LocatorInterface implementation.

public static setTableLocator(LocatorInterface $tableLocator) : void
Parameters
$tableLocator : LocatorInterface

Instance of a locator to use.


        
On this page

Search results