Symfony2 array of forms?

后端 未结 4 931
孤城傲影
孤城傲影 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

    Symfony3:

    $datas = $em->findAll();
    
    foreach ($datas as $key=>$data)
    {
       $form_name = "form_".$key;
       $form = $this->get('form.factory')->createNamed( 
          $form_name, 
          SomeType::class, 
          $data
       );
       $views[] = $form->createView();
    }
    return $this->render(someView, ["forms" => $views]);
    

提交回复
热议问题