2014-10-01 2 views
0

필드가있는 엔티티 ChoiceQuestion이 있습니다. 옵션. 옵션은 배열로 정의됩니다. Symfony2에서Symfony2 엔티티 필드의 선택

<?php 

namespace Survey\SurveyBundle\Entity; 

use Survey\SurveyBundle\Entity\BaseQuestion; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity 
* @author GKLESSE 
* 
*/ 
class RadioQuestion extends BaseQuestion { 
    const TYPE = 'radio'; 
    /** 
    /* @ORM\Column(type="array") 
    */ 
    protected $options; 
    /** 
    * @var integer 
    */ 
    protected $id; 

    /** 
    * @var string 
    */ 
    protected $question; 

    /** 
    * @var integer 
    */ 
    protected $questionOrder; 

    /** 
    * @var \Survey\SurveyBundle\Entity\Survey 
    */ 
    protected $survey; 

    public function __construct(){ 
     $this->questiontype = self::TYPE; 
    } 

    /** 
    * Set options 
    * 
    * @param array $options 
    * @return RadioQuestion 
    */ 
    public function setOptions($options) 
    { 
     $this->options = $options; 

     return $this; 
    } 

    /** 
    * Get options 
    * 
    * @return array 
    */ 
    public function getOptions() 
    { 
     return $this->options; 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set question 
    * 
    * @param string $question 
    * @return RadioQuestion 
    */ 
    public function setQuestion($question) 
    { 
     $this->question = $question; 

     return $this; 
    } 

    /** 
    * Get question 
    * 
    * @return string 
    */ 
    public function getQuestion() 
    { 
     return $this->question; 
    } 

    /** 
    * Set questionOrder 
    * 
    * @param integer $questionOrder 
    * @return RadioQuestion 
    */ 
    public function setQuestionOrder($questionOrder) 
    { 
     $this->questionOrder = $questionOrder; 

     return $this; 
    } 

    /** 
    * Get questionOrder 
    * 
    * @return integer 
    */ 
    public function getQuestionOrder() 
    { 
     return $this->questionOrder; 
    } 

    /** 
    * Set survey 
    * 
    * @param \Survey\SurveyBundle\Entity\Survey $survey 
    * @return RadioQuestion 
    */ 
    public function setSurvey(\Survey\SurveyBundle\Entity\Survey $survey = null) 
    { 
     $this->survey = $survey; 

     return $this; 
    } 

    /** 
    * Get survey 
    * 
    * @return \Survey\SurveyBundle\Entity\Survey 
    */ 
    public function getSurvey() 
    { 
     return $this->survey; 
    } 
    /** 
    * @var string 
    */ 
    protected $questiontype; 


    /** 
    * Set questiontype 
    * 
    * @param string $questiontype 
    * @return RadioQuestion 
    */ 
    public function setQuestiontype($questiontype) 
    { 
     $this->questiontype = $questiontype; 

     return $this; 
    } 

    /** 
    * Get questiontype 
    * 
    * @return string 
    */ 
    public function getQuestiontype() 
    { 
     return $this->questiontype; 
    } 
    /** 
    * @var \Doctrine\Common\Collections\Collection 
    */ 
    protected $answers; 


    /** 
    * Add answers 
    * 
    * @param \Survey\SurveyBundle\Entity\Answer $answers 
    * @return RadioQuestion 
    */ 
    public function addAnswer(\Survey\SurveyBundle\Entity\Answer $answers) 
    { 
     $answers->setQuestion($this); 
     $this->answers[] = $answers; 

     return $this; 
    } 

    /** 
    * Remove answers 
    * 
    * @param \Survey\SurveyBundle\Entity\Answer $answers 
    */ 
    public function removeAnswer(\Survey\SurveyBundle\Entity\Answer $answers) 
    { 
     $this->answers->removeElement($answers); 
    } 

    /** 
    * Get answers 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 
    public function getAnswers() 
    { 
     return $this->answers; 
    } 
} 

나는 양식을 만들려면 그 형태의 한 부분으로 "선택"으로 그 실체의 옵션을 표시합니다.

나는 구현 다음

$form = $this->createFormBuilder(); 
$form->add($question->getQuestionOrder(), 'choice',array('label' => $question->getQuestion(), 'choices' => $question->getOptions())); 
$formbuilder->add($question->getId(), 'checkbox',array('label' => $question->getQuestion(), 'choices' => $question->getOptions())); 

을 그러나 내가 나에게 아무 의미 다음과 같은 오류가 페이지를 검사 할 때 :

The option "choices" does not exist. Known options are: "action", "attr", "auto_initialize", "block_name" ... 

Symfony2은 선택이 존재하지 않음을 알려줍니다 오는 방법 그것은 분명히 폼 셋업의 일부이기 때문에?

이것을 구현하는 올바른 방법은 무엇입니까?

+0

. 다른 비슷한 양식이 있습니까? – frumious

+0

여러 선택 양식 유형에 대해 확인란 유형을 사용하지 않는다고하더라도 이름을 찾았습니다. 옵션을 Multiple로 선택해야합니다. – Gekko09

답변

0

오류가 발견되었습니다. 대신 여러 선택을 렌더링하는 형태 유형 "체크 상자를"사용

, 당신은 옵션 "선택"을 사용해야합니다

바로 내 보이는
"multiple" => true, "expanded" => true 
+0

조금 혼란 스러운데, 질문에있는 예제는'checkbox'가 아닌'choice' 타입을 사용합니까? – frumious

+0

그리고 그것은 내 잘못입니다. 나는 전체 코드를 제출하지 않았습니다 (앞으로 할 일입니다). 체크 박스 유형의 선택 필드 아래에 다른 필드가 있었으며 선택 사항을 거기에 추가했습니다 (여러 개의 체크 박스가 표시 될 것이라고 생각 함). 혼란을 드려 죄송합니다. – Gekko09

+0

아하! 걱정 마세요. 다행 이군요. 원래의 질문을 편집하는 아이디어 일 수 있습니다. 그 순간에 답은 궁금해하지 않으므로 비슷한 문제가있는 사람에게는 도움이되지 않습니다. – frumious