Symfony2 array of forms?

后端 未结 4 929
孤城傲影
孤城傲影 2021-02-10 09:06

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:23

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

提交回复
热议问题