Forms Symfony3-处理文件上传/编辑的好方法是什么?

Forms Symfony3-处理文件上传/编辑的好方法是什么?,forms,file,upload,symfony,Forms,File,Upload,Symfony,cookbook解释代码与NewAction()控制器配合得很好,但是如何编辑具有此技术文件的表单 此编辑控制器始终擦除文件,即使该文件不存在。这是一个问题,当我只想编辑文本,而不是文件本身 public function editAction(Request $request, Model $model) { $deleteForm = $this->createDeleteForm($model); $editForm = $this->createForm(Mo

cookbook解释代码与NewAction()控制器配合得很好,但是如何编辑具有此技术文件的表单

此编辑控制器始终擦除文件,即使该文件不存在。这是一个问题,当我只想编辑文本,而不是文件本身

public function editAction(Request $request, Model $model)
{
    $deleteForm = $this->createDeleteForm($model);
    $editForm = $this->createForm(ModelType::class, $model);
    $editForm->handleRequest($request);

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

            $file = $model->getPicture();
            $fileName = substr(md5(uniqid()), 0, 10) . '.' . $file->guessExtension();

            $uploadDir = $this->container->getParameter('kernel.root_dir') . '/../web/' . Model::UPLOAD_DIR;
            $file->move($uploadDir, $fileName);

            $model->setPicture($fileName);

        $em = $this->getDoctrine()->getManager();
        $em->persist($model);
        $em->flush();

        return $this->redirectToRoute('my_route', array('id' => $model->getId()));
    }

嗨,你修好了吗?如何处理?如果在实体类hi的upload()方法中有(null===$this->getFile()){return;},您是否修复了该问题?如何操作?如果(null===$this->getFile()){return;}在实体类的upload()方法中