2014-07-15 1 views
0

심포니 2를 사용하여 매우 간단한 앱을 만들려고합니다.Symfony2 - FOS UserBundle - 데이터베이스의 데이터로 드롭 다운 목록으로 레지스터 양식 덮어 쓰기

FOS UserBundle을 HWI Oauth2와 함께 설치 및 구성했습니다.

잘 작동하지만 등록 양식을 수정하여 데이터베이스에있는 데이터가 포함 된 드롭 다운 목록이 doctrine에 의해 제거되도록하고 싶습니다.

Symfony doc에서 아무 것도 발견되지 않았습니다. .

누구든지 제안을 할 수 있습니까?

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
     ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle')) 

     ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle')) 


     **/**** This Works and give a dropdownlist but i want to get this list from database instead of hard coded data how can I achieve that ? *****/** 
     ->add('status_type', 'choice', array(
     'choices' => array(
      '' => 'Please Select...', 
      'developper' => 'Android Developper', 
      'architect' => 'Android or Mobile Architect', 
      'mobile' => 'Mobile Developper', 
      'web and mobile' => 'Web and Mobile Developper', 
     ))) 

     ->add('plainPassword', 'repeated', array(
      'attr' => array('class' => 'form-control'), 
      'type' => 'password', 
      'options' => array('translation_domain' => 'FOSUserBundle'), 
      'first_options' => array('label' => 'form.password'), 
      'second_options' => array('label' => 'form.password_confirmation'), 
      'invalid_message' => 'fos_user.password.mismatch', 
     )) 
    ; 
} 

답변

1

이것은 예제 코드입니다. 사용자 정의 쿼리를 필요로하는 경우

$builder->add('status_type', 'entity', array(
    'class' => 'AcmeDemoBundle:Status', 
    'property' => 'status_name', 
)); 

가 나 : 당신이 http://symfony.com/it/doc/current/reference/forms/types/entity.html

에서 관련 문서를 찾을 수 있습니다, 자세한 내용은

$builder->add('status_type', 
       'entity', 
       array(
        'class'=>'AcmeDemoBundle:Status', 
        'property'=>'status_name', 
        'query_builder' => function ($repository) 
        { 
         return $repository->createQueryBuilder('s') 
           ->where('s.status_type = ?1') 
           ->setParameter(1, 'basic') 
           ->add('orderBy', 's.sort_order ASC'); 
        } 
        ) 
      ); 

(당신은 당신의 스키마에 대한 쿼리를 조정해야합니다)