简体   繁体   English

实体编辑表单中的“文件类型”字段

[英]FileType field in Entity edit form

I have a user entity. 我有一个用户实体。 At registration, a file is required. 注册时需要文件。 When I edit this user entity, I want to be able to see the uploaded file and modify it. 当我编辑该用户实体时,我希望能够看到上传的文件并对其进行修改。

I have this form : 我有这个表格:

$builder->add('email', EmailType::class  , ['label' => 'Adresse mail']);
$builder->add('photo', FileType::class);

Controller : 控制器:

$form = $this->createForm(ProfilTutoreFormType::class, $user)

Entity : 实体 :

 /**
 * @var string
 */
protected $email;

 /**
 * @var string
 * @ORM\Column(name="photo", type="string", length=255)
 */
private $photo;

Email field is populated with user's email but photo field stays blank. 电子邮件字段填充了用户的电子邮件,但照片字段保持空白。

First you must copy the file to the system. 首先,您必须将文件复制到系统。 You should then save the new path to the database. 然后,您应该将新路径保存到数据库。 Examine the example here https://symfony.com/doc/current/controller/upload_file.html 在此处检查示例https://symfony.com/doc/current/controller/upload_file.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM