私はsymfonyにエンティティフォームがあります。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を返す理由を教えてください。回避策は何ですか? –
フォームがオブジェクトにマップされ、送信され、バインドされている場合、なぜそれからヌルを取得したいのですか? – goto
何か問題がある場合は、例外をスローすることはできますが、nullを返すことはできません。検証のためにAssertsを使用することができます。本当に、回避策は何ですか? –