php - Symfony file field empty on edit -
i reading while found nothing works me. entity
/** * @orm\column(type="string") * * @assert\notblank(message="molimo unesite pdf ili word fajl.") * @assert\file(mimetypes={ "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.ms-powerpoint", "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}) */ private $body;
this form
// problem empty field on edit persist! form expect filetype db sends string!!! ->add('body', filetype::class, [ //'data_class' => null,// <-- if change nothing happened. 'label' => 'word ili pdf dokument', 'invalid_message' =>'id posta nije validan', 'attr' => [ 'class' => 'form-group', ]])
everything simple , made following docs. have entity contains few properties 1 of them files ($body). files set saved in web/uploads/post/ . when go edit page error:
"the form's view data expected instance of class symfony\component\httpfoundation\file\file, a(n) string. can avoid setting "data_class" option null or adding view transformer transforms string instance of symfony\component\httpfoundation\file\file".
if set data_status => null field empty.
what need link example working, data transformer maybe?
you can around creating new file() in editaction. this:
/** * @route("/edit/{yourentity}", name="entity_edit") * * @return response */ public function editaction(request $request, yourentity yourentity) { $body = new file($this->getparameter('your_files_directory') . '/' . $yourentity->getbody()); $yourentity->setbody($body); // rest of editaction }
Comments
Post a Comment