Skip to content

Tables and configuration ​

Fetch plugin tables using their plugin alias, such as $this->fetchTable('Data.Countries') in a controller. The supplied classes use Tools' table base class and retain some compatibility helpers from earlier plugin versions.

Table aliasMain purpose
Data.ContinentsContinent tree and country association
Data.CountriesCountry names, ISO codes, phone codes, status, and timezone offsets
Data.StatesCountry subdivisions
Data.CitiesCity records and postal-code searches
Data.PostalCodesPostal codes and location searches
Data.LanguagesLanguage codes, locales, fallback locales, and status
Data.TimezonesTimezone names, offsets, canonical entries, and aliases
Data.CurrenciesCurrency records and exchange-rate integration
Data.AddressesAddresses attached to host records
Data.MimeTypesMIME type and extension records
Data.MimeTypeImagesImages associated with MIME types

Counties, Districts, and Locations are legacy models. Do not start a new application with them; their tables are not created by the supplied migrations.

Country associations ​

When using only the country table, disable associations whose tables you have omitted. Configure this during application bootstrap, before a country table instance is created:

php
use Cake\Core\Configure;

Configure::write('Data.Country.Continent', false);
Configure::write('Data.Country.State', false);
Configure::write('Data.Country.Timezone', false);

The values must be the boolean false; an unset key leaves the association enabled. Disable the reverse timezone-to-country association with Data.Timezone.Country if your installation omits countries.

Language helpers ​

php
$languages = $this->fetchTable('Data.Languages');
$active = $languages->getActive()->all();
$primary = $languages->getPrimaryLanguages()->all();
$namesById = $languages->getList();
$namesByCode = $languages->codeList();

getActive() filters active rows. getPrimaryLanguages() selects rows whose locale equals their fallback locale. The list helpers filter active rows; they do not mean that every locale variant is included.

Named connections ​

Plugin aliases do not select a database connection automatically. Configure the table locator before creating plugin table instances if you migrated to a named connection:

php
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;

$locator = TableRegistry::getTableLocator();
$locator->setConfig('Data.Countries', [
    'connection' => ConnectionManager::get('reference'),
]);

Set the connection for associated plugin tables too. All associations involved in a query or save must use compatible database connections.

Released under the MIT License.