2016-09-05 4 views
0

매핑되지 않은 4 개의 필드가있는 양식이 있습니다. 각 필드는 [0, n] 파일을 가질 수 있습니다.Symfony3 - collectionType에 대한 파일 제약 조건 확인

여기 (잘 작동) 내 FormType입니다 : 각 파일에 대한

$builder    
     ->add('identityProofs', CollectionType::class, array(
      'entry_type' => FileType::class, 'allow_add' => true, 'prototype' => true, 'label' => false)) 
     ->add('articlesOfAssociations', CollectionType::class, array(    
      'entry_type' => FileType::class, 'allow_add' => true, 'prototype' => true, 'label' => false)) 
     ->add('registrationProofs', CollectionType::class, array(
      'entry_type' => FileType::class, 'allow_add' => true, 'prototype' => true, 'label' => false)) 
     ->add('shareolderDeclarations', CollectionType::class, array(
      'entry_type' => FileType::class, 'allow_add' => true, 'prototype' => true, 'label' => false))   
    ; 

, 나는이 maxSize 같은 제약 조건을 추가해야합니다. 내가 주석을 사용하지 않고 그것에 대해 어떤 문서도 찾을 수 없다. (내가 맵핑 된 클래스를 가지고 있지 않기 때문에 사용할 수 없다.) 내가 클래스를 추가해야합니까, 또는 그 (이미 시도, 그것은 작동하지 않습니다) 같은 것을 수행 할 수

당신은 내부 양식 유형 (파일)에 대한 제약 조건을 통과해야
->add('articlesOfAssociations', CollectionType::class, array(
      'constraints' => array(
       new Collection(
        ['fields' => ['File' => new File(['maxSize' => '10k'])]])), 

답변

1

아닌 부모 (컬렉션) 하나.

이렇게하려면 entry_options 컬렉션 유형 옵션을 사용해야합니다. 이 옵션의 값은 입력 양식 유형 (귀하의 경우 FileType)의 모든 인스턴스에 전달됩니다. 따라서 다음과 같이 될 수 있습니다.

+0

매력처럼 작동합니다. 감사! – user2733521

관련 문제