Symfony2 array of forms?

后端 未结 4 1620
庸人自扰
庸人自扰 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:20

    Create the forms in an array, but give each one a unique name. I've changed it to formbuilder which might not be ideal for you but hopefully something similar will work. I'm also not certain about putting in new SomeType rather than 'form', see http://api.symfony.com/2.4/Symfony/Component/Form/FormFactory.html#method_createNamedBuilder.

    $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));
    

提交回复
热议问题