然后,假设 Locale :: getDefault()在语言列表中,您可以使用 empty_data 指定默认值: $ form-> add('agentCity','language',array('empty_data'=> Locale :: getDefault())); 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() 解决方案 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())); 这篇关于symfony 2中本地默认国家/地区的国家/地区字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 05-31 06:23