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 3.1 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.1
      • 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
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • 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

    Configuration for aliases.

  • $_fallbacked protected
    array

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

  • $_instances protected
    array

    Instances that belong to the registry.

  • $_options protected
    array

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

Method Summary

  • _create() protected

    Wrapper for creating table instances

  • _getClassName() protected

    Gets the table class name.

  • clear() public

    Clears the registry of configuration and instances.

  • config() public

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

  • 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.

  • remove() public

    Removes an instance from the registry.

  • set() public

    Set an instance.

Method Detail

_create() ¶ protected

_create(array $options): Cake\ORM\Table

Wrapper for creating table instances

Parameters
array $options

The alias to check for.

Returns
Cake\ORM\Table

_getClassName() ¶ protected

_getClassName(string $alias, array $options = []): string

Gets the table class name.

Parameters
string $alias

The alias name you want to get.

array $options optional

Table options array.

Returns
string

clear() ¶ public

clear(): void

Clears the registry of configuration and instances.

Returns
void

config() ¶ public

config(string|null $alias = null, array|null $options = null): array

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

The options that can be stored are those that are recognized by get() If second argument is omitted, it will return the current settings for $alias.

If no arguments are passed it will return the full configuration array for all aliases

Parameters
string|null $alias optional

Name of the alias

array|null $options optional

list of options for the alias

Returns
array
Throws
RuntimeException
When you attempt to configure an existing table instance.

exists() ¶ public

exists(string $alias): bool

Check to see if an instance exists in the registry.

Parameters
string $alias
Returns
bool

genericInstances() ¶ public

genericInstances(): array

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

get() ¶ public

get(string $alias, array $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 Table::__construct(), but the key className is also recognized.

If $options does not contain className CakePHP will attempt to construct the class name based on the alias. For example 'Users' would result in App\Model\Table\UsersTable being attempted. 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. This className can use a plugin short class reference.

If you use a $name that 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.

If no table option is passed, the table name will be the underscored version of the provided $alias.

If no connection option is passed the table's defaultConnectionName() method will be called to get the default connection name to use.

Parameters
string $alias

The alias name you want to get.

array $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.

remove() ¶ public

remove(string $alias): void

Removes an instance from the registry.

Parameters
string $alias
Returns
void

set() ¶ public

set(string $alias, Cake\ORM\Table $object): Cake\ORM\Table

Set an instance.

Parameters
string $alias
Cake\ORM\Table $object
Returns
Cake\ORM\Table

Property Detail

$_config ¶ protected

Configuration for aliases.

Type
array

$_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

$_instances ¶ protected

Instances that belong to the registry.

Type
array

$_options ¶ protected

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

Type
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