Please help me because I cannot believe my eyes.
I refuse to use a third-party plugin to upload files and refuse to create a separate object for the file / document. I just need a simple file upload that I would do in Zend / Laravel, etc.
I have a table of accounts with the last attachment name “attachment”, I want to save my disinfected name here (for example: 123421_filename.jpg), the upload form and the download went well.
the code is here:
$file=$form['attachment']->getData();
$fileName=$file->getClientOriginalName();
$sanitizedFilename=rand(1, 99999).'_'.$fileName;
$dir='files/'.$userId.'/';
$file->move($dir, $sanitizedFilename);
...
$invoice->setAttachment($sanitizedFilename);
$em = $this->getDoctrine()->getManager();
$em->persist($invoice);
The first problem I encountered, and don’t know how to solve it, was to use the edit form. I have a formbuilder
$builder->add('attachment', 'file',array('data_class'=>null))
"" , , , data_class= > null.., , , - , NULL, , .
$builder->add('attachment', 'text')
, - ... ? Document?!
( , , laravel, " ". symfony , .. , , , ? , , ?)
, , ( , , $builder- > add ('attachment', file ', array (' data_class '= > null ))
, ?
public function editAction($id)
....
$invoice = $em->getRepository('AppBundle:Invoice')->find($id);
..
if ($form->isValid()) {
$oldFileName=$invoice->getAttachment(); //this is null
$oldFileName=$invoice->getId(); //this returns the invoice id
$oldFileName=$invoice->getValue(); //returns invoice value
echo 'old: '.$oldFileName.'<br/>';
exit();
}
, -, , , ? ?
, , -, $invoice, -
if ($form->isValid()) {
$sameInvoice= $em->getRepository('AppBundle:Invoice')->find(20);
$oldFileName=$sameInvoice->getAttachment();
$oldFileName=$sameInvoice->getId();
echo 'old: '.$oldFileName.'<br/>';
exit();
, , , , , .. ?
? ( ?.. , , ... "" ). " t invoice- > , , , , ?!
