2 回答

TA貢獻1872條經驗 獲得超4個贊
我認為您不應該在 ImageNewFileType 中添加mapped => false 選項。
https://symfony.com/doc/current/reference/forms/types/form.html#mapped
正如您在文檔中看到的,寫入對象時該字段將被忽略。

TA貢獻1862條經驗 獲得超7個贊
錯誤發生在 ImageNewFileType 內部,因為屬性 'mapped' => false,表單未在 ImageNew 實體的文件字段中設置上傳的文件信息,所以我替換了此:
class ImageNewFileType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'file', FileType::class,
[
'mapped' => false,
'required' => false,
'attr' => array(
'accept' => 'image/*',
)
]
);
}
}
這樣:
class ImageNewFileType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'file', FileType::class,
[
'mapped' => true(or live this empty because by default it is true),
'required' => false,
'attr' => array(
'accept' => 'image/*',
)
]
);
}
}
- 2 回答
- 0 關注
- 149 瀏覽
添加回答
舉報