我从Symfony \ Component \ Form \ Extension \ Core \ Type \ FileType添加到我的表单类型FileType;
namespace App\Form;
use App\Entity\Order;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class OrderType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('subject',null,[
'required' => true
])
->add('key')
->add('type')
->add('message')
->add('file',FileType::class)
->add('submit', SubmitType::class, ['label' => 'Save'])
;
}
当我尝试运行此命令时,出现此错误:
具有键“值,属性,格式,id,名称,全名,已禁用,标签,label_format,multipart,block_prefixes,unique_block_prefix,translation_domain,cache_key,错误,有效,数据,必需,大小, label_attr,help,help_attr,化合物,方法,操作,已提交,类型“不存在。
答案 0 :(得分:0)
您可以传入attr
参数
$builder
->add('subject',null,[
'required' => true
])
->add('key')
->add('type')
->add('message')
->add('file', FileType::class, [ //<-----HERE
'attr' => ['class'=>'myClass'], //<-----HERE
]) //<-----HERE
->add('submit', SubmitType::class, ['label' => 'Save'])
;
文档中的更多信息:https://symfony.com/doc/current/reference/forms/types/form.html#attr