5098 Posts in 1518 Topics by 1115 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 416 Views |
-
Get the country name from the 2 digit country code

3 May 2012 at 12:50pm
Is there anyway I can easily get the country name from the 2 letter country code.
I am populating a dropdown from the values stored in a table for country, however these are stored as NZ, US, etc. Is there a simple way I can do this without populating a table with code/name matches and doing a join?
//get countries
$countryMap = array();
$countryMap[""] = "ALL COUNTRIES";
$sql = new SQLQuery();
$sql->select = array(
'Country'
);
$sql->from = array(
'Member'
);
$sql->where = array(
"Country !='' AND Country IS NOT NULL"
);
$sql->orderby('Country');$result = $sql->execute();
foreach($result as $row){
$countryMap[$row['Country']] = $row['Country'];
}
return new FieldSet(
new LiteralField('Countries',"<b>Selected Countries:".$this->MemberCountry."</b>"),
new ListboxField('MemberCountry','Country',$countryMap,'',null,true)
); -
Re: Get the country name from the 2 digit country code

4 May 2012 at 6:40pm
Geoip::countryCode2name() might be what you want.
http://api.silverstripe.org/2.4/sapphire/misc/Geoip.html#methodcountryCode2name
-
Re: Get the country name from the 2 digit country code

21 November 2012 at 1:43am
Is there a Geoip::countryCode2name around in Silverstripe 3.0?
-
Re: Get the country name from the 2 digit country code

23 November 2012 at 10:59pm Last edited: 23 November 2012 11:16pm
Possibly a better way doning this, but this works in SS3:
public function getCMSFields()
{
$f = parent::getCMSFields();$f->addFieldToTab("Root.Main", new CountryDropdownField("VisitCountry", _t("SOME_PROJECT.Country", "Country")), "Metadata");
return $f;
}public function CountryNice()
{
$locale = Zend_Locale::getLocaleToTerritory($this->VisitCountry);
return Locale::getDisplayRegion($locale, i18n::get_locale());
return Zend_Locale::getTranslation($this->VisitCountry, "country", i18n::get_locale())
}
| 416 Views | ||
|
Page:
1
|
Go to Top |



