zend-modules / isocodes-country
dev-master
2015-10-28 13:23 UTC
Requires
- php: >=5.3.23
- zendframework/zend-i18n: 2.4.8
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2020-01-10 15:27:28 UTC
README
安装
-
在您的 composer.json 中添加此项目
"require": { "zend-modules/isocodes-country": "dev-master" }
-
现在,通过运行以下命令让 composer 下载
isocodes-country
$ php composer.phar update
适配器
StaticAdapter
静态适配器使用内部国家名称数组。这是默认适配器,无需额外配置。
$countryManager = new \IsoCodes\Country\Country();
Pdo
此适配器使用 PDO 连接从数据库获取数据。您可以在 data\iso_3166.sql
中找到数据库表的 MySQL 备份。
$dbh = new \Pdo('mysql:host:localhost;dbname=isodata;', 'root', '');
$adapter = new \IsoCodes\Country\Adapter\Pdo($dbh);
$countryManager = new \IsoCodes\Country\Country($adapter);
您也可以传递 PDO::__construct
参数。
$adapter = new \IsoCodes\Country\Adapter\Pdo(array(
'dsn' => 'mysql:host:localhost;dbname=isodata;',
'username' => 'root',
'password' => ''
));
$countryManager = new \IsoCodes\Country\Country($adapter);
ZendDB
此适配器使用 Zend\Db\Adapter\Adapterinterface
对象从数据库中检索国家信息。
例如
$dbAdapter = $serviceManager->get('Zend\Db\Adapter\Adapter');
$adapter = new \IsoCodes\Country\Adapter\ZendDB($dbAdapter);
$countryManager = new \IsoCodes\Country\Country($adapter);
翻译
默认输出为英文。
要更改输出区域设置,请将翻译器的区域设置设置为适合您需求的区域。例如,如果您希望输出西班牙语的国家名称
$countryManager->getTranslator()->setLocale('es');
数据源
此模块提供的数据来自 Debian 的 iso-codes 软件包。