diggindata/yii2-countrylist

Extension to provide a translated list of country names with country codes for the Yii framework

Installs: 269

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

dev-master 2022-11-13 15:57 UTC

This package is auto-updated.

Last update: 2024-12-13 20:34:31 UTC


README

Country List Extension for Yii 2


This package is based on umpirsky/country-list

It contains an extension for the Yii framework to get a translated list of country names.

Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist diggindata/yii2-countrylist "*"

or add

"diggindata/yii2-countrylist": "*"

to the require section of your composer.json.

Then run composer install or composer update.

Usage

The extension looks at the configured Yii application language Yii::$app->language. So if the language is configured to e.g. de, it takes the corresponding translation list from the umpirsky package.

Once the extension is installed, simply use the list in your forms as follows:

use diggindata\countrylist\CountryList;    
<?= $form->field($model, 'countryCode')->dropDownList(CountryList::getList()) ?>

Alternatively, you may add the extension as an application component.

Add the following to your config/web.php file:

...
'components' => [
    'countryList' => [
        'class' => 'diggindata\countrylist\CountryList',
    ],

You can the use it like this:

<?= $form->field($model, 'countryCode')->dropDownList(Yii::$app->countryList->getList()) ?>