tigrov / yii2-country
使用Intl扩展的Yii2国家数据。
1.1.11
2019-07-19 15:19 UTC
Requires
- php: >=5.5.0
- tigrov/intldata: ~1.0
- yiisoft/yii2: ~2.0.13
Suggests
- rinvex/countries: Allows access to additional data of countries. For PHP >=7.0 only.
README
该库提供对Intl扩展数据的访问,包括地区、子地区、国家、语言、区域、货币和时区等信息。它还包括有关大陆、区域、城市和度量系统的额外类。
主要类
- 大陆
- 区域
- 子区域
- 国家 (ActiveRecord)
- 区域 (ActiveRecord)
- 城市 (ActiveRecord)
- 区域
- 语言
- 货币
- 时区
- 度量系统
限制
自1.1.0版起,需要Yii >= 2.0.13和PHP >= 5.5
安装
通过composer安装此扩展是首选方式。
运行以下命令:
php composer.phar require --prefer-dist tigrov/yii2-country
或将其添加到您的composer.json
文件的require部分:
"tigrov/yii2-country": "~1.0"
配置
扩展安装后,在config.php
中配置迁移,并应用迁移:
return [ // ... 'controllerMap' => [ 'migrate' => [ 'class' => 'yii\console\controllers\MigrationController', ], ], // ... ];
yii migrate
使用
类可以访问Tigrov/intldata的静态方法。
// 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');
一些类还有额外的静态方法来获取更多信息。
每个类都有以下方法和属性(可能是魔法属性):
// 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;
例如
$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;
附加信息
- 要获取关于国家的附加信息(国旗、代码、边界和其他信息),请使用以下库:
https://github.com/rinvex/countries$country->rinvex
或 https://github.com/antonioribeiro/countries - 有关Intl扩展数据的更多信息,请参阅:
https://github.com/Tigrov/intldata
http://intl.rmcreative.ru/tables?locale=en_US
https://php.ac.cn/manual/book.intl.php