2014-07-22 1 views
1

미리 정의 된 값을 가진 선택 상자를 사용하고 싶습니다.정적 목록이있는 Symfony2 선택

namespace xx\xxx\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 
/** 
* Task 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="xx\xxx\Entity\TaskRepository") 
*/ 
class Task 
{ 

//// 

/** 
* @Assert\Choice(choices = {"MONTHLY", "WEEKLY"}, message = "Select frequency") 
* @ORM\Column(name="frequency", type="text") 
*/ 
private $frequency;  
} 

하는 TaskType를 사용 : - 단지, 주간 및 월간 값 수

$builder->add('frequency'); 

가 제대로 유효성을 검사 입력을 보여줍니다 나는 작업 개체가 있습니다. 하지만 선택 상자를 사용하고 싶습니다.

$builder->add('frequency', 'collection', array(
      'type' => 'choice', 
      'options' => array(
       'choices' => array(
        'MONTHLY' => 'Monthly', 
        'WEEKLY' => 'Weekly', 
       ) 
      ) 
     ) 
    ) 

또는 : 나는 시도

$builder->add('frequency', 'collection', array(
      'type' => 'choice', 
     ) 
    ) 

을하지만 두 가지 방법이 난 단지 어떤 선택 상자와 라벨을 얻을. 내가 뭘 잘못하고 있니? 어쩌면 더 나은 접근법이 있을까요?

답변