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']);
// 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);Method Summary
- 
          clear() public static deprecatedClears the registry of configuration and instances. 
- 
          exists() public static deprecatedCheck to see if an instance exists in the registry. 
- 
          get() public static deprecatedGet a table instance from the registry. 
- 
          getTableLocator() public staticReturns a singleton instance of LocatorInterface implementation. 
- 
          remove() public static deprecatedRemoves an instance from the registry. 
- 
          set() public static deprecatedSet an instance. 
- 
          setTableLocator() public staticSets singleton instance of LocatorInterface implementation. 
Method Detail
clear() ¶ public static
clear(): voidClears the registry of configuration and instances.
Returns
voidexists() ¶ public static
exists(string $alias): boolCheck to see if an instance exists in the registry.
Parameters
- 
                string$alias
- The alias to check for. 
Returns
boolget() ¶ public static
get(string $alias, array $options = []): Cake\ORM\TableGet a table instance from the registry.
See options specification in {@link TableLocator::get()}.
Parameters
- 
                string$alias
- The alias name you want to get. 
- 
                array$options optional
- The options you want to build the table with. 
Returns
Cake\ORM\TablegetTableLocator() ¶ public static
getTableLocator(): Cake\ORM\Locator\LocatorInterfaceReturns a singleton instance of LocatorInterface implementation.
Returns
Cake\ORM\Locator\LocatorInterfaceremove() ¶ public static
remove(string $alias): voidRemoves an instance from the registry.
Parameters
- 
                string$alias
- The alias to remove. 
Returns
voidset() ¶ public static
set(string $alias, Cake\ORM\Table $object): Cake\ORM\TableSet an instance.
Parameters
- 
                string$alias
- The alias to set. 
- 
                Cake\ORM\Table$object
- The table to set. 
Returns
Cake\ORM\TablesetTableLocator() ¶ public static
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): voidSets singleton instance of LocatorInterface implementation.
Parameters
- 
                Cake\ORM\Locator\LocatorInterface$tableLocator
- Instance of a locator to use. 
Returns
void