powderblue / sf-continent-country-type
Symfony 表单类型,可以按洲显示世界各国的列表
v4.0.0
2024-09-13 12:50 UTC
Requires
- php: ^8.2.23
- symfony/config: ^5.4|^6.4
- symfony/dependency-injection: ^5.4|^6.4
- symfony/form: ^5.4|^6.4
- symfony/framework-bundle: ^5.4|^6.4
- symfony/http-foundation: ^5.4|^6.4
- symfony/http-kernel: ^5.4|^6.4
- symfony/intl: ^5.4|^6.4
- symfony/options-resolver: ^5.4|^6.4
Requires (Dev)
- phpstan/phpstan: ^1.12.3
- phpunit/phpunit: ^11.3.5
- squizlabs/php_codesniffer: ^3.10.2
This package is auto-updated.
Last update: 2024-09-13 12:51:17 UTC
README
一个提供名为 "ContinentCountryType" 的新表单类型的 Symfony 扩展包。它类似于 Symfony 的 CountryType
,但允许开发者按洲分组国家。显示的国家和洲列表可以轻松自定义。
屏幕截图
(以下示例使用了 Select2 渲染下拉列表。)
安装
- 运行
composer require powderblue/sf-continent-country-type
- 更新您的项目
app/AppKernel.php
文件,并将扩展包添加到$bundles
数组中
$bundles = [ // ... new PowderBlue\SfContinentCountryTypeBundle\PowderBlueSfContinentCountryTypeBundle(), ];
使用
在表单类型的 buildForm
方法中,将 ContinentCountryType::class
作为类型指定。
use PowderBlue\SfContinentCountryTypeBundle\Form\Type\ContinentCountryType; // ... $builder // ... ->add('country', ContinentCountryType::class, [ 'label' => 'Country', 'attr' => [ 'placeholder' => 'Country', ], ]) ;
配置
以下列出了所有配置选项及其默认值
# config.yml powder_blue_sf_continent_country_type: # The path of the file containing the countries (and continents) that should appear in the dropdown file: "%bundle_root_dir%/Resources/data/continent_country.csv" # Group the countries by continent in the dropdown? group_by_continent: true # The ID of the service used to parse the countries file. It should implement `...\Provider\ContinentCountryProviderInterface`. provider: powder_blue_sf_continent_country_type.provider.continent_country_csv_file