使用细枝在symfony3.4中创建具有相同实体的多个记录的特殊形式

时间:2019-03-31 18:18:45

标签: symfony-3.4

我正在尝试创建一个允许用户添加同一实体的多个记录的表单

我要创建这个

1 https://imgur.com/XMOUe65 2 https://imgur.com/fvHMBtb

我的实体

命名空间qcmBundle \ Entity;

将Doctrine \ ORM \ Mapping用作ORM;

/ **  * 题  *  * @ORM \ Table(name =“问题”)  * @ORM \ Entity(repositoryClass =“ qcmBundle \ Repository \ questionRepository”)  * / 课堂问题 {     / **      * @var int      *      * @ORM \ Column(name =“ id”,type =“ integer”)      * @ORM \ Id      * @ORM \ GeneratedValue(strategy =“ AUTO”)      * /     私人$ id;

/**
 * @var string
 *
 * @ORM\Column(name="leabel", type="string", length=255)
 */
private $leabel;

/**
 * @var string
 *
 * @ORM\Column(name="allQuestionText", type="text")
 */
private $allQuestionText;


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

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

    return $this;
}

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

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

    return $this;
}

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

}

我的动作     公共功能testAction(Request $ request)     {         $ question =新问题();

    $form = $this->createFormBuilder($question)
    ->add('leabel', TextType::class,['label' => 'Question','attr'=>['class'=>'form-control'],])
    ->add('allQuestionText', TextareaType::class,['label' => 'Text','attr'=>['class'=>'form-control'],])
    ->add('save', SubmitType::class, ['label' => 'Ajouter','attr'=>['class'=>'btn btn-primary'],])
    ->getForm();

    return $this->render("@qcm/Default/test.html.twig",['form' => $form->createView(),]);
}

0 个答案:

没有答案