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 4.4 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.4
      • 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
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
      • Association
      • Behavior
      • Exception
      • Locator
      • Rule
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class TableLocator

Provides a default registry/factory for Table objects.

Namespace: Cake\ORM\Locator

Property Summary

  • $_config protected
    array<string, array|null>

    Configuration for aliases.

  • $_fallbacked protected
    array<Cake\ORM\Table>

    Contains a list of Table objects that were created out of the built-in Table class. The list is indexed by table alias

  • $allowFallbackClass protected
    bool

    Whether fallback class should be used if a table class could not be found.

  • $fallbackClassName protected
    string

    Fallback class to use

  • $instances protected
    array<string, \Cake\ORM\Table>

    Instances that belong to the registry.

  • $locations protected
    array<string>

    Contains a list of locations where table classes should be looked for.

  • $options protected
    array<string, array>

    Contains a list of options that were passed to get() method.

Method Summary

  • __construct() public

    Constructor.

  • _create() protected

    Wrapper for creating table instances

  • _getClassName() protected

    Gets the table class name.

  • addLocation() public

    Adds a location where tables should be looked for.

  • allowFallbackClass() public

    Set if fallback class should be used.

  • clear() public

    Clears the registry of configuration and instances.

  • createInstance() protected

    Create an instance of a given classname.

  • exists() public

    Check to see if an instance exists in the registry.

  • genericInstances() public

    Returns the list of tables that were created by this registry that could not be instantiated from a specific subclass. This method is useful for debugging common mistakes when setting up associations or created new table classes.

  • get() public

    Get a table instance from the registry.

  • getConfig() public

    Returns configuration for an alias or the full configuration array for all aliases.

  • remove() public

    Removes an repository instance from the registry.

  • set() public

    Set a Table instance.

  • setConfig() public

    Stores a list of options to be used when instantiating an object with a matching alias.

  • setFallbackClassName() public

    Set fallback class name.

Method Detail

__construct() ¶ public

__construct(array<string>|null $locations = null)

Constructor.

Parameters
array<string>|null $locations optional

Locations where tables should be looked for. If none provided, the default Model\Table under your app's namespace is used.

_create() ¶ protected

_create(array<string, mixed> $options): Cake\ORM\Table

Wrapper for creating table instances

Parameters
array<string, mixed> $options

The alias to check for.

Returns
Cake\ORM\Table

_getClassName() ¶ protected

_getClassName(string $alias, array<string, mixed> $options = []): string|null

Gets the table class name.

Parameters
string $alias

The alias name you want to get. Should be in CamelCase format.

array<string, mixed> $options optional

Table options array.

Returns
string|null

addLocation() ¶ public

addLocation(string $location): $this

Adds a location where tables should be looked for.

Parameters
string $location

Location to add.

Returns
$this

allowFallbackClass() ¶ public

allowFallbackClass(bool $allow): $this

Set if fallback class should be used.

Controls whether a fallback class should be used to create a table instance if a concrete class for alias used in get() could not be found.

Parameters
bool $allow

Flag to enable or disable fallback

Returns
$this

clear() ¶ public

clear(): void

Clears the registry of configuration and instances.

Returns
void

createInstance() ¶ protected

createInstance(string $alias, array<string, mixed> $options): Cake\Datasource\RepositoryInterface

Create an instance of a given classname.

Parameters
string $alias
array<string, mixed> $options
Returns
Cake\Datasource\RepositoryInterface

exists() ¶ public

exists(string $alias): bool

Check to see if an instance exists in the registry.

Parameters
string $alias

The alias to check for.

Returns
bool

genericInstances() ¶ public

genericInstances(): array<Cake\ORM\Table>

Returns the list of tables that were created by this registry that could not be instantiated from a specific subclass. This method is useful for debugging common mistakes when setting up associations or created new table classes.

Returns
array<Cake\ORM\Table>

get() ¶ public

get(string $alias, array<string, mixed> $options = []): Cake\ORM\Table

Get a table instance from the registry.

Tables are only created once until the registry is flushed. This means that aliases must be unique across your application. This is important because table associations are resolved at runtime and cyclic references need to be handled correctly.

The options that can be passed are the same as in {@link \Cake\ORM\Table::__construct()}, but the className key is also recognized.

Options

  • className Define the specific class name to use. If undefined, CakePHP will generate the class name based on the alias. For example 'Users' would result in App\Model\Table\UsersTable being used. If this class does not exist, then the default Cake\ORM\Table class will be used. By setting the className option you can define the specific class to use. The className option supports plugin short class references {@link \Cake\Core\App::shortName()}.
  • table Define the table name to use. If undefined, this option will default to the underscored version of the alias name.
  • connection Inject the specific connection object to use. If this option and connectionName are undefined, The table class' defaultConnectionName() method will be invoked to fetch the connection name.
  • connectionName Define the connection name to use. The named connection will be fetched from {@link \Cake\Datasource\ConnectionManager}.

Note If your $alias uses plugin syntax only the name part will be used as key in the registry. This means that if two plugins, or a plugin and app provide the same alias, the registry will only store the first instance.

Parameters
string $alias

The alias name you want to get. Should be in CamelCase format.

array<string, mixed> $options optional

The options you want to build the table with. If a table has already been loaded the options will be ignored.

Returns
Cake\ORM\Table
Throws
RuntimeException
When you try to configure an alias that already exists.

getConfig() ¶ public

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

Returns configuration for an alias or the full configuration array for all aliases.

Parameters
string|null $alias optional
Returns
array

remove() ¶ public

remove(string $alias): void

Removes an repository instance from the registry.

Parameters
string $alias
Returns
void

set() ¶ public

set(string $alias, Cake\Datasource\RepositoryInterface $repository): Cake\ORM\Table

Set a Table instance.

Parameters
string $alias

The alias to set.

Cake\Datasource\RepositoryInterface $repository

The Table to set.

Returns
Cake\ORM\Table

setConfig() ¶ public

setConfig(array<string, mixed>|string $alias, array<string, mixed>|null $options = null): $this

Stores a list of options to be used when instantiating an object with a matching alias.

Parameters
array<string, mixed>|string $alias
array<string, mixed>|null $options optional
Returns
$this

setFallbackClassName() ¶ public

setFallbackClassName(string $className): $this

Set fallback class name.

The class that should be used to create a table instance if a concrete class for alias used in get() could not be found. Defaults to Cake\ORM\Table.

Parameters
string $className

Fallback class name

Returns
$this

Property Detail

$_config ¶ protected

Configuration for aliases.

Type
array<string, array|null>

$_fallbacked ¶ protected

Contains a list of Table objects that were created out of the built-in Table class. The list is indexed by table alias

Type
array<Cake\ORM\Table>

$allowFallbackClass ¶ protected

Whether fallback class should be used if a table class could not be found.

Type
bool

$fallbackClassName ¶ protected

Fallback class to use

Type
string

$instances ¶ protected

Instances that belong to the registry.

Type
array<string, \Cake\ORM\Table>

$locations ¶ protected

Contains a list of locations where table classes should be looked for.

Type
array<string>

$options ¶ protected

Contains a list of options that were passed to get() method.

Type
array<string, array>
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