我想知道在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',
));
}
有什么建议吗? 问候,本