Class TableContainer
Dependency injection container for Tables. Will create Tables as if fetchTable() was called with default options.
Register as a delegate in your Application::services() function before any auto-wire delegates.
Property Summary
-
$_tableLocator protected
Cake\ORM\Locator\LocatorInterface|nullTable locator instance
-
$defaultTable protected
string|nullThis object's default table alias.
Method Summary
-
fetchTable() public
Convenience method to get a table instance.
-
get() public
Finds an entry of the container by its identifier and returns it.
-
getTableLocator() public
Gets the table locator.
-
has() public
Returns true if the container can return an entry for the given identifier. Returns false otherwise.
-
setTableLocator() public
Sets the table locator.
Method Detail
fetchTable() ¶ public
fetchTable(class-string<T>|string|null $alias = null, array<string, mixed> $options = []): $alias is class-string<T> ? T : \Cake\ORM\Table
Convenience method to get a table instance.
Templates
T
of \Cake\ORM\Table Parameters
-
class-string<T>|string|null$alias optional The alias name you want to get. Should be in CamelCase format. If
nullthen the value of $defaultTable property is used.-
array<string, mixed>$options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Returns
$alias is class-string<T> ? T : \Cake\ORM\TableThrows
Cake\Core\Exception\CakeExceptionIf `$alias` argument and `$defaultTable` property both are `null`.
See Also
get() ¶ public
get(string $id): Table
Finds an entry of the container by its identifier and returns it.
Parameters
-
string$id
Returns
TablegetTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfacehas() ¶ public
has(string $id): bool
Returns true if the container can return an entry for the given identifier. Returns false otherwise.
has($id) returning true does not mean that get($id) will not throw an exception.
It does however mean that get($id) will not throw a NotFoundExceptionInterface.
Parameters
-
string$id
Returns
boolsetTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface$tableLocator LocatorInterface instance.
Returns
$this