https://github.com/tigrov/yii2-country
Country data for Yii2 using Intl extension and more.
https://github.com/tigrov/yii2-country
city continent country currency division intl language locale measurement-systems region subdivision subregion timezone yii2-extension
Last synced: 6 months ago
JSON representation
Country data for Yii2 using Intl extension and more.
- Host: GitHub
- URL: https://github.com/tigrov/yii2-country
- Owner: Tigrov
- License: mit
- Created: 2017-05-28T16:03:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-19T15:28:21.000Z (about 6 years ago)
- Last Synced: 2024-10-12T15:23:53.650Z (about 1 year ago)
- Topics: city, continent, country, currency, division, intl, language, locale, measurement-systems, region, subdivision, subregion, timezone, yii2-extension
- Language: PHP
- Homepage:
- Size: 73.6 MB
- Stars: 15
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Country data for Yii2
=====================The library provides access to Intl extension data for information about regions, sub-regions, countries, languages, locales, currencies and timezones. Also it has additional classes for information about continents, divisions, cities and measurement systems.
[](https://packagist.org/packages/Tigrov/yii2-country)
[](https://travis-ci.org/Tigrov/yii2-country)The main classes:
- Continent
- Region
- Subregion
- Country (ActiveRecord)
- Division (ActiveRecord)
- City (ActiveRecord)
- Locale
- Language
- Currency
- Timezone
- MeasurementSystemLimitation
------------Since 1.1.0 requires Yii >= 2.0.13 and PHP >= 5.5
Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist tigrov/yii2-country
```or add
```
"tigrov/yii2-country": "~1.0"
```to the require section of your `composer.json` file.
Configuration
---------
Once the extension is installed, configure migrations in `config.php`:```php
return [
// ...
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrationController',
],
],
// ...
];
```and apply migrations:
```
yii migrate
```Usage
-----The classes have access to static methods of [Tigrov/intldata](https://github.com/Tigrov/intldata):
```php
// Get list of codes.
ClassName::codes();// Get a boolean indicating whether data has a code.
ClassName::has($code);// Get list of names.
ClassName::names();// Get name by code.
ClassName::name($code);// E.g.
Country::names();
Currency::name('USD');
Locale::codes();
Timezone::has('America/New_York');
```And some of the classes have additional static methods to get more information.
Also each of the classes has follow methods and attributes (perhaps magic):
```php
// Create a model by code
ClassName::create($code);// All models of a class
ClassName::all();// Code of the model
$model->code;// Name of the model
$model->name;
```**For example:**
```php
$continents = Continent::all();
$europe = Continent::create('EU');
$europe->code; // 'EU'
$europe->name; // 'Europe'// List of countries
$europe->countries;$us = Country::create('US');
$us->code; // 'US'
$us->name; // 'United States' (depends of the current locale)// List of divisions (states)
$us->divisions;// List of cities
$us->cities;
```
Addition
--------- For additional information about countries (flags, codes, borders and other) use a library
https://github.com/rinvex/countries
```$country->rinvex```
or https://github.com/antonioribeiro/countries
- For more information about Intl extension data see
https://github.com/Tigrov/intldata
http://intl.rmcreative.ru/tables?locale=en_US
http://php.net/manual/book.intl.phpLicense
-------[MIT](LICENSE)