これが事です。
1 つのビューで 2 つのフォームを作成したい。1 つはエンティティにバインドされ、もう 1 つは .csv を配置して内部の情報をキャッチして最初のエンティティを埋めるファイル タイプです。
私はすでに最初のものを作成しましたが、2番目のものを作成して同じビューに正しく統合して、互いに戦わないようにする方法がわかりません。ここに私のファイルがあります (csv プロセスはまだここにありません)
私のコントローラー:
public function adminAction()
    {
    $form = $this->createForm(new StudentsType, null);
    $formHandler = new StudentsHandler($form, $this->get('request'), $this->getDoctrine()->getEntityManager());
    if( $formHandler->process() )
    {
        return $this->redirect( $this->generateUrl('EnsgtiEnsgtiBundle_ens'));
    }
    return $this->render('EnsgtiEnsgtiBundle:Appli:admin.html.twig', array(
        'form' => $form->createView(),
    ));
    }
最初のフォーム:
class StudentsType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('nom', 'text')->setRequired(false)
            ->add('prenom', 'text')
            ->add('email', 'email')
            ->add('codeEtape', 'text')
            ->add('file', new StudentsListType)->SetRequired(false);
    }
    public function getName()
    {
        return 'ensgti_ensgtibundle_studentstype';
    }
    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Ensgti\EnsgtiBundle\Entity\Students',
        );
    }
}
ハンドラー:
class StudentsHandler
{
    protected $form;
    protected $request;
    protected $em;
    public function __construct(Form $form, Request $request, EntityManager $em)
    {
        $this->form    = $form;
        $this->request = $request;
        $this->em      = $em;
    }
    public function process()
    {
        if( $this->request->getMethod() == 'POST' )
        {
            $this->form->bindRequest($this->request);
            if( $this->form->isValid() )
            {
                $this->onSuccess($this->form->getData());
                return true;
            }
        }
        return false;
    }
    public function onSuccess(Students $students)
    {
        $this->em->persist($students);
        $this->em->flush();
    }
}
2 番目のフォーム:
class StudentsListType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
        ->add('', 'file');
    }
    public function getName()
    {
        return 'ensgti_ensgtibundle_studentslisttype';
    }
}
ハンドラー:
class StudentsListHandler
{
    protected $form;
    protected $request;
    protected $em;
    public function __construct(Form $form, Request $request, EntityManager $em)
    {
        $this->form    = $form;
        $this->request = $request;
        $this->em      = $em;
    }
    public function process()
    {
        if( $this->request->getMethod() == 'POST' )
        {
            $this->form->bindRequest($this->request);
            if( $this->form->isValid() )
            {
                //$this->onSuccess($this->form->getData());
                print_r($this->form->getData());
                return true;
            }
        }
        return false;
    }
    public function onSuccess(/*StudentsList $studentsList*/)
    {
        //$this->em->persist($studentsList);
        //$this->em->flush();
        echo 'Petit test';
    }
}
このコードを使用すると、次のようになります。
クラス「Ensgti\EnsgtiBundle\Entity\Students」には、プロパティ「file」もメソッド「getFile()」もメソッド「isFile()」も存在しません
ファイルタイプのないエンティティにバインドしているため、これは正常です。私は初心者なのでドキュメントを読み続けていますが、すべてを理解するのはまだ難しいです。同じビューでエンティティにバインドされていないが、csv 処理を介して保持される 2 つのフォームを作成する方法はありますか??