2014-04-23 4 views
0

symfony2에서 콜백을 사용하여 양식을 검증하려고하지만 콜백이 호출되지 않습니다. 콜백이있는 클래스는 컬렉션을 통해 기본 폼에서 호출됩니다. 여기 Symfony2 - 콜렉션 유효성 검사기

내 코드는

...

Main 클래스 :

class InscriptionType extends AbstractType 
{ 
    /** 
    * @param FormBuilderInterface $builder 
    * @param array $options 
    */ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('inscriptionReponses','collection',array('label'=>false, 
                  'type'=>new InscriptionReponseType(), 
                  'error_bubbling'=>false, 
                  'by_reference'=>false)) 
     ; 
    } 
} 

InscriptionReponse 클래스 : 내가 잘못 이해하지

use Symfony\Component\Validator\Constraints as Assert; 
use Symfony\Component\Validator\ExecutionContextInterface; 

/** 
* InscriptionReponse 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="Ptolemee\ColloqueBundle\Entity\InscriptionReponseRepository") 
* @Assert\Callback(methods={"formValidation"}) 
*/ 

class InscriptionReponse 
{ 

    /* ... some code ... */ 

    public function formValidation(ExecutionContextInterface $context) 
    { 
     die('not dying ?'); 
    }  

} 

... 어떤 도움은 매우 될 것 고맙습니다. tahnks.

니콜라스.

http://symfony.com/doc/current/reference/constraints/Callback.html

대신

/** 
* @Assert\Callback(methods={"formValidation"}) 
*/ 

class InscriptionReponse 
{ 

의 당신은 함수 자체

class InscriptionReponse 
{ 

/** 
* @Assert\Callback 
*/ 
    public function formValidation(ExecutionContextInterface $context) 
    { 
     die('not dying ?'); 
    } 

방법 당신이 위의 주석을 이동해야합니다 : 문서에 기록 된 사항에

답변

0

기본 사용 된 버전 2.3에서 유효합니다. 2.4 아마도 now

+0

안녕하세요, 요 답변 주셔서 감사합니다 ... 실제로 2.4를 사용하므로 주석을 mvoved. 하지만 여전히 작동하지 않습니다 ... 결코 콜백을 전달하지 마십시오 ... – nikophil

+0

양식 옵션을 설정해보십시오 : 'error_bubbling'=> true –

+0

어느 쪽이든 true 또는 false로 작동하지 않습니다 .... :/: – nikophil

1

@Assert \ Valid를 포함 엔터티의 컬렉션에 추가하면 컬렉션의 콜백 함수가 호출됩니다.

의 비문이 InscriptionResponses의 컬렉션을 가지고 있다고 가정 해 봅시다 :

class Inscription 
{ 
    /** 
    * @Assert\Valid() 
    */ 
    private $inscriptionResponses; 
} 

class InscriptionResponse 
{ 
    /** 
    * @Assert\Callback 
    */ 
    public function formValidation(ExecutionContextInterface $context) 
    { 
     die('dying'); 
    } 
} 

이것은 error_bubbling 옵션의 값에 관계없이 작동합니다.