文件未插入编辑表单

时间:2019-06-28 17:10:35

标签: forms file symfony edit

我在插入用户个人资料时正在插入文件,我的问题是在编辑个人资料时必须再次插入文件,如何将插入的文件放入编辑表单中?

这是我的代码:

编辑:

/**
 *
 * @Route("/{id}/edit", name="profil_edit")
 * @Method({"GET", "POST"})
 */
public function editAction(Request $request, User $user) {

    $editForm = $this->createForm('AppBundle\Form\UserTypeEdit', $user);
    $editForm->handleRequest($request);

    if ($editForm->isSubmitted() && $editForm->isValid()) {
        $this->getDoctrine()->getManager()->flush();
        $this->addFlash('success', $this->get('translator')->trans('title.edit_success'));
        return $this->redirectToRoute('user_edit', array('id' => $user->getId()));
    }

    return $this->render('AppBundle:User:editUser.html.twig', array(
        'user' => $user,
        'edit_form' => $editForm->createView()
    ));
}

UserTypeEdit:

  public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', TextType::class,array( 'required' => true))
            ->add('lastname', TextType::class,array( 'required' => true))



            ->add('addresse', TextType::class,array( 'required' => true))

            ->add('Mobile', TextType::class,array( 'required' => true))


            ->add('fax', null)
            ->add('file',FileType::class,array('data_class' => null,'required'=>false))
            ;

    }

0 个答案:

没有答案