2

我正在尝试使用 symfony 2 管理问卷,代码部分有效。我收到这个错误

给定“布尔”、“字符串”类型的预期参数

我在控制器中的代码如下:

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将属性“值”作为布尔值。

当我删除该错误时,该错误正在消失,$formBuilder->add($formBuilder2);但我需要显示该问题的复选框。

你对解决这个问题有什么想法吗?

4

0 回答 0