如何在Symfony / Doctrine中为FileType的输入设置默认值?

问题描述 投票:0回答:1

就像TextType和其他具有默认属性value => $ myValue的类型一样。我试图在更新表单中更新用户的图片时,尝试将数据库中的用户现有图像设置为默认值。我一直在阅读Doctrine Assets文档,但没有运气https://symfony.com/doc/current/components/asset.html

$form =$this->createFormBuilder($contact)

   ->add('picture', FileType::class, ['required'=>false, 'label' => 'Add 
        Profile picture (jpg file)'])

    ->add('firstname', TextType::class, array('attr'=>
       array('value'=>'mydefaultvalue','class' => 'form-control')))
php symfony doctrine-orm doctrine md5
1个回答
1
投票

只需将值放在对象中:

$contact->setFirstname('Primo');
$form =$this->createFormBuilder($contact)
   ->add('picture', FileType::class, ['required'=>false, 'label' => 'Add 
      Profile picture (jpg file)'])
   ->add('firstname', TextType::class, array('attr'=>
      array('value'=>'mydefaultvalue','class' => 'form-control')))
© www.soinside.com 2019 - 2024. All rights reserved.