silvercommerce / geozones
添加通用的“地理区域”,包括所有特定国家的区域,并允许将这些区域分类为不同的区域
1.1.1
2018-11-23 17:09 UTC
Requires
- silverstripe/framework: ~4.0
- silverstripe/siteconfig: ~4.0
Suggests
- silverstripe/cms: Add full content management support to your site
README
添加ISO-3166-2 "Subdivisions" 的列表,并允许将这些区域划分为 "区域"(可用于地理标识)
初始列表基于Debian项目提供的数据生成。更多详情请参阅
https://salsa.debian.org/iso-codes-team/iso-codes/blob/master/data/iso_3166-2.json
注意 此模块仅提供可以在您的SilverStripe项目中使用的数据。
安装
最简单的方法是通过composer安装
composer require silvercommerce/geozones
设置
所有GeoZone设置都与SiteConfig
相关联,要设置新的区域或添加新的区域,可以通过访问网站设置并选择“GeoZones”选项卡来完成。
区域选择字段
此模块还提供了一个RegionSelectionField
,它是一个简单的基于ajax的表单字段,可以用于根据预定义的国家代码过滤区域列表。
您可以通过以下方式将RegionSelectionField
添加到您的代码中
use SilverCommerce\GeoZones\Forms\RegionSelectionField; $form = Form::create( $this, 'PostageForm', $fields = FieldList::create( DropdownField::create( 'Country', 'Country', array_change_key_case( i18n::getData()->getCountries(), CASE_UPPER ) ), RegionSelectionField::create( "Region", "County/State", "Country" // name of the field in this form responsible for setting a country code ) ), $actions = FieldList::create( FormAction::create( "doSetPostage", _t('SilverCommerce\ShoppingCart.Search', "Search") ) ), $required = RequiredFields::create(array( "Country", "Region" )) );
注意 您必须向同一表单中添加一个字段,该字段负责为RegionSelectionField
设置有效的国家代码(ISO 3166 2位字符),以便其能够工作。