2013-10-23 4 views
1
MyType 형태 locale 필드에 추가 할, 그래서 넣어

:Symfony2 로케일 타입의 폼 요소

$builder->add('locale', 'locale', array(
    'label'  => 'user.locale', 
    'required' => true, 
)); 

이 나에게 가능한 로케일의 전체 목록을 렌더링 그러나 때문에 이러한 유형의 기본 choices 배열 입니다 :

'choices' => Intl::getLocaleBundle()->getLocaleNames() 

난 단지 en, depl을 표시하고 싶습니다. 어떻게 그 언어로 출력을 제한 할 수 있습니까?

가장 좋은 해결책은 config.yml에이 목록을 정의하는 것입니다.

답변

0

사용이 :

$builder->add('locale', 'locale', array(
    'label'  => 'user.locale', 
    'required' => true, 
    'choices' => array('en' => 'English', 'de' => 'Deutsch', 'pl' => 'Polish') 
)); 

구성에서이 값을 얻기 위해 documentation를 참조하십시오.

편집 : Djuro Mandinic 덕분에 이전 대답의 오류를 지적 해 주므로 choices 배열에 키와 값이 있어야합니다.