我正在尝试使用symfony 2管理调查问卷,代码部分正常运行。 我收到此错误
“Boolean”类型的预期参数,“string”给出
我在控制器中的代码如下:
public function generateForm($questionnaire, $evaluation)
{
//Get question array collection
$questions = $questionnaire->getQuestions();
$formBuilderQuestionnaire = $this->createFormBuilder();
$i = 0;
//Make a loop for each question
foreach($questions as $question)
{
//Create an answer form
$answer = new Answers($question, $evaluation);
$formBuilder = $this->get('form.factory')->createNamedBuilder($i, 'form', $answer);
//Add a answer text box with the question as label
$formBuilder->add('answerText' , 'textarea', array(
'required' => false,
'label' => $question->getQuestionText()
));
if($question->getHasMultipleAnswers() == 1)
{
//Get subquestions
$subQuestions = $question->getSubQuestions();
//Initiate var j
$j = 0;
//Make a loop for each subanswers of a question
foreach($subQuestions as $subQuestion)
{
if($question->getMultipleAnswersAllowed() == 1)
{
//Create a subanswer entity for each subQuestion
$subAnswer = new subAnswers($subQuestion, $answer);
//Create a sub answer form
$formBuilder2 = $this->get('form.factory')->createNamedBuilder($j, 'form', $subAnswer);
$formBuilder2->add('value');
$j++;
}
else
{
//Get the different choices
$choices[$subQuestion->getId()] = $subQuestion->getSubQuestionsText();
}
}
if($question->getMultipleAnswersAllowed() == 0)
{
$formBuilder->add('AnswerChoice', 'choice', array(
'choices' => $choices,
'required' => true,
'expanded' => true
));
}
else
{
if(isset($formBuilder2))
{
$formBuilder->add($formBuilder2);
}
}
$choices = NULL;
}
$formBuilderQuestionnaire->add($formBuilder);
$i++;
}
//Create the form
$form = $formBuilderQuestionnaire->getForm();
return $form;
}
我的实体subAnswers
将属性“value”作为布尔值。
当我删除$formBuilder->add($formBuilder2);
时,错误消失,但我需要显示问题的复选框。
你对解决这个问题有什么想法吗?