Symfony 2.3:访问表单底层对象的正确方法?

时间:2015-05-26 13:58:53

标签: symfony symfony-forms symfony-2.3

我想知道在symfony 2.3中访问表单底层对象的正确方法是什么? 我应该用这个:

$underlyingObject = $builder->getData();
echo get_class($underlyingObject) ; // prints App\MyBundle\Entity\Foobar

或那:

$builder->addEventListener(FormEvents::PRE_SET_DATA,function (FormEvent $formEvent) {
    $underlyingObject = $formEvent->getData() ;
    echo get_class($underlyingObject) ; // prints App\MyBundle\Entity\Foobar too !
});

这里是setDefaultOptions方法,它定义了映射对象的类:

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => ' App\MyBundle\Entity\Foobar',
    ));

}

有什么建议吗? 问候,本

0 个答案:

没有答案