나는 심포니 엔티티 양식이 있습니다 Symfony : Type/Form에서 null을 반환 할 수 있습니까?
class MyType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
...
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'LogicielBundle\Entity\FichierGroup',
'intention' => $this->getName() . '_token'
));
}
그러나 POST_SUBMIT 이벤트
, 나는 널 (엔터티)를 반환하지 싶다. 나는이 테스트 있지만 작동하지 않는 : 당신이 나를$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
.... my condition ...
$event->setData(null);
});
도와 드릴까요? 감사합니다 :)
왜 null을 반환 하시겠습니까? 해결 방법은 무엇입니까? –
양식이 객체에 매핑되고 제출되고 바인드 된 경우 왜 그 객체에서 null을 가져 오려고합니까? – goto
잘못된 것이 있으면 예외를 throw 할 수 있지만 null을 throw 할 수는 없습니다. 유효성 검사를 위해 Asserts를 사용할 수 있습니다. 정말로, 해결 방법은 무엇입니까? –