如何从国家代码获取国家/地区名称?

Akh*_*tel 9 magento

$collection = Mage::getModel('custom/table')->getCollection();
Run Code Online (Sandbox Code Playgroud)

我有一个自定义表,有一个字段country_code.

现在我将这个$ collection传递给我的javascript并使用其中的变量.

现在我想显示国家/地区名称而不是国家/地区代码.

有什么方法可以使用联接查询或其他任何方式在我的集合中添加国家/地区名称?

所以在传递给js之前我想在我的集合对象中使用国家名称.

liy*_*kat 25

Magento将国家/地区名称存储在区域设置文件中,以便您可以根据语言更改国家/地区名称.

如果您有国家/地区代码,并且想要获取国家/地区名称,请使用以下代码:

$country_name=Mage::app()->getLocale()->getCountryTranslation($country_code);
Run Code Online (Sandbox Code Playgroud)

或者你也可以试试

// $countryCode looks like "US"
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
echo $country->getName(); /
Run Code Online (Sandbox Code Playgroud)

如果我能为您提供更多帮助,请告诉我.