Symfony form to retrieve data from a CSV file and inject it into the database

  csv, forms, php, symfony, twig

I don’t understand how to do with a FileType form to retrieve data from csv and inject it into database.

With a normal form, I retrieve my data without problems.


        $data = new Data();

        $form = $this->createFormBuilder($data)
                        ->add('Nbmessage', IntegerType::class)


        if($form->isSubmitted() && $form->isValid())

// import.html.twig

    {{ form_start(form)}}

    {{ form_widget(form) }}
        <button type="submit" class="btn btn-success">Add</button>

    {{ form_end(form)}}

But I would like to get this data format located in a csv, with a Symfony Form.

Here is where I am for the moment, after many attempts

        $form2 = $this->createFormBuilder()
        ->add('submitFile', FileType::class)

        if ($request->getMethod('post') == 'POST') {


        if ($form2->isSubmitted() && $form2->isValid()) {

            $file = $form2->get('submitFile');



I’ve been looking for a week … I really don’t understand how to do it.

Source: Symfony Questions