powderblue/sf-continent-country-type

Symfony 表单类型,可以按洲显示世界各国的列表

v4.0.0 2024-09-13 12:50 UTC

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