Symfony2 array of forms?

后端 未结 4 1619
庸人自扰
庸人自扰 2021-02-10 08:59

Is it possible to create and render and array of forms I know about collections but they don\'t really fit in my idea?

What I want is something like this

Contro

4条回答
  •  执笔经年
    2021-02-10 09:19

    Just create your forms in array:

    $data = $em->findAll();
    for ($i = 0; $i < $n; $i++) {
        $forms[] = $this->container
            ->get('form.factory')
            ->createNamedBuilder('form_'.$i, new SomeType, $data)
            ->getForm()
            ->createView();
    }
    
    return $this->render(someView, array("forms" => $forms));
    

    UPDATED

    As mentioned by edlouth you can create each form named separately. I updated my code.

提交回复
热议问题