Answer the question
In order to leave comments, you need to log in
FileType, why is the data_class property needed?
Good day dear!
I'm learning Symfony3, I went through half a dozen options for creating / processing a field for uploading several files at once.
Among other things, when creating/adding a field of the FileType type , this field itself has the data_class attribute . Why the form itself has such an attribute - I understand, but why FileType has this attribute is not entirely clear to me. VendorFile
- I created this class myself, for testing
Example code:
class VendorType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('www')
->add('file1', FileType::class, [
'multiple' => 'multiple',
'data_class' => VendorFile::class, //вот эта строчка кода у меня вызывает непонятки
])
->add('Готово', SubmitType::class);
}
data_class
, for what purposes can it be used? If not difficult, please give a simple example of how and when it can be used? If possible, I would also like to hear a little theory on this topic. VendorFile
? I imagined that the properties of this class should be initialized with the properties of the UploadFile object, but apparently this is not the case.
Answer the question
In order to leave comments, you need to log in
->add('file1', FileType::class, [
'multiple' => 'multiple', <-- Это булево свойство и оно не будет работать в данном случае
'data_class' => VendorFile::class, //вот эта строчка кода у меня вызывает непонятки
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question