내 웹 사이트에서 .pdf 파일을 업로드하는 방법을 찾고 있습니다.Symfony2 FileType 입력 형식은 항상 null을 반환합니다.
문자열의 파일 이름을 포함하는 엔티티를 만들었습니다. 엔티티 매핑 있습니다 :
<field name="pdf" type="string" column="pdf" length="200" nullable="true"/>
양식 어디 입력 파일 :
$builder
->add('pdf', FileType::class, array('label' => 'Fiche de paie'))
/* other input */
;
내 양식의보기 :
{{ form_start(form) }}
{{ form_row(form._token) }}
<div class="modal-body row">
<div class="col-md-6 col-sm-8">
/* other input */
{{ form_row(form.pdf) }}}
</div>
<div class="col-md-6 col-sm-8">
/* other input */
</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 }) }}
그리고 컨트롤러가 :
if ($form->isSubmitted() && $form->isValid()) {
$pdf = $salaire->getPdf();
if ($pdf == null) { /* Always true */
$salaire->setPdf('test');
}
/* operations to extract the file name and set it to the pdf variable in salaire */
$em->persist($salaire);
$em->flush();
return $this->redirectToRoute('salaires_index', array("id" => $remuneration->getId()));
}
T 그는 파일을 입력하더라도 입력 값을 얻을 때
->salaire->getPdf()
결과는 항상 null입니다.
처음 엔 내 엔티티에있는 문자열에 양식 입력 FileType을 설정했기 때문에 생각했지만 필자는 엔티티에서 UploadedFile 변수에 값을 설정하려고 시도했지만 그 결과는 여전히 null입니다.
도움 주셔서 감사합니다.
도움을 주셔서 감사합니다.하지만 도움이되지 않았습니다. – Julien