Class TableRegistry
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']);
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);
Method Summary
-
getTableLocator() public static
Returns a singleton instance of LocatorInterface implementation.
-
setTableLocator() public static
Sets singleton instance of LocatorInterface implementation.
Method Detail
getTableLocator() ¶ public static
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Returns a singleton instance of LocatorInterface implementation.
Returns
Cake\ORM\Locator\LocatorInterface
setTableLocator() ¶ public static
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): void
Sets singleton instance of LocatorInterface implementation.
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator Instance of a locator to use.
Returns
void