Sunday, 15 August 2010

symfony2 - Why does data_class leads to LogicException? -



symfony2 - Why does data_class leads to LogicException? -

i have form type (field_type) extends text , have data_class. passing entity instance form via event listener leads logicexception:

the form's view info expected instance of class entity, a(n) string. can avoid error setting "data_class" alternative null or adding view transformer transforms a(n) string instance of entity.

public function buildform(formbuilderinterface $builder, array $options) { $builder->add('field', 'field_type', $opts); $builder->addeventlistener(formevents::post_set_data, function (formevent $event) use($options) { ... $form = $event->getform(); $form->get('field')->setdata($entity); }); }

$entity instance of data_class. form type has view info transformer, too.

field type:

public function buildform(formbuilderinterface $builder, array $options) { $builder->addviewtransformer($this->viewtransformer, true); } public function setdefaultoptions(optionsresolverinterface $resolver) { $resolver->setdefaults(array( 'data_class' => 'entity', 'invalid_message' => 'the given id invalid!', 'required' => true )); } public function getparent() { homecoming 'text'; }

everything works fine except part of data_class. if remove data_class works.

why need remove part?

symfony2 symfony-forms symfony-2.5

No comments:

Post a Comment