Easy Admin - 在Show Action中显示完整的国家/地区名称

chr*_*isp 8 symfony symfony2-easyadmin easyadmin

我有一个需要一个国家的地址实体.在相关的表格中,我使用的是Symfony的CountryType,它显示了一个用户友好的国家选择,并将其缩写存储在实体中(例如德国的DE或瑞士的CH).

要在管理面板的show动作中显示地址'country,我在以下行中使用以下行easy_admin.yaml:

- { property: country, label: 'address.entity.country' }
Run Code Online (Sandbox Code Playgroud)

问题:

这仅显示缩写而不是国家的实际名称.我怎么能改变呢?

国家地址实体:

/**
 * @ORM\Column(type="string", length=255)
 */
private $country;
Run Code Online (Sandbox Code Playgroud)

Dir*_*ten 5

我认为最好的解决方案是使用内置的Symfony intl组件.

composer require symfony/intl 安装组件.

然后在你的实体中你可以use Symfony\Component\Intl\Intl;.

我建议在您的实体上创建一个名为countryName的新属性,每当您设置国家/地区代码时,都会调用该属性的setter.你的二传手看起来像这样:

public function setCountryName (string $countryCode) 
{
    $this->countryName = Intl::getRegionBundle()->getCountryName(strtoupper($countryCode));
}
Run Code Online (Sandbox Code Playgroud)

然后在您的yaml文件中更改address.entity.countryaddress.entity.countryName.