I am working on uploading a .pdf file on my website.
I created an Entity that contains the file name in a string. There is an entity mapping:
<field name="pdf" type="string" column="pdf" length="200" nullable="true"/>
The form in which I enter the file:
$builder
->add('pdf', FileType::class, array('label' => 'Fiche de paie'))
;
View of my form:
{{ form_start(form) }}
{{ form_row(form._token) }}
<div class="modal-body row">
<div class="col-md-6 col-sm-8">
{{ form_row(form.pdf) }}}
</div>
<div class="col-md-6 col-sm-8">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" id="save">{% trans %}Save{% endtrans %}</button>
</div>
{{ form_end(form, { 'render_rest': false } ) }}
And there is a controller:
if ($form->isSubmitted() && $form->isValid()) {
$pdf = $salaire->getPdf();
if ($pdf == null) {
$salaire->setPdf('test');
}
$em->persist($salaire);
$em->flush();
return $this->redirectToRoute('salaires_index', array("id" => $remuneration->getId()));
}
The problem is that even if I enter the file when I get the input value with
->salaire->getPdf()
the result is always zero.
At first I thought it was because I set the FileType input form to a string in my entity, but I tried to set it in the UploadedFile variable in my entity, and the result was still null.
Thank you for your help.
source
share