symfony2: setting the value of a form field outside the form, inside a controller action

后端 未结 3 1093
無奈伤痛
無奈伤痛 2020-12-30 08:55

I need to set the value of a symfony2 form element. I use a doctrine2 entity, a Symfony\\Component\\Form\\AbstractType and the createForm() method inside my

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 09:28

    If you try fill file upload field - it's wrong idea. Ask yourself: what data should be there? If an user upload an image, then in this field will be a path to the image on his local system. But then after file is uploaded you change its name and location, so you don't need info about this path and you just don't keep it.

    The appropriate way should be left empty upload field below (or above, or wherever you have it ;) ) image. Then after form is submitted and if the field is not empty you should change edited image.

提交回复
热议问题