问题
How to use Locale::getDefault()
for country field or in choice field with country names?
I have tried ->add('agentCity','country')
but I don't know how to use Locale::getDefault()
回答1:
You can easily create a dropdown list of languages using the language
field type: http://symfony.com/doc/current/reference/forms/types/language.html.
Then you can specify the default value using empty_data
, assuming that Locale::getDefault()
is in the languages list:
$form->add('agentCity', 'language', array('empty_data' => Locale::getDefault()));
来源:https://stackoverflow.com/questions/27514842/country-field-for-local-default-country-in-symfony-2