php - The form's view data is expected to be an instance of another class error creating form instance of another entity -


i following error when trying create form entity pass through view.

i have 2 entities in context courseguide , courseguiderow , pass through form view of courseguiderowtype view - how can this?

the form's view data expected instance of class crmpicco\coursebundle\entity\courseguide, instance of class crmpicco\coursebundle\entity\courseguiderow. can avoid error setting "data_class" option null or adding view transformer transforms instance of class crmpicco\coursebundle\entity\courseguiderow instance of crmpicco\coursebundle\entity\courseguide.

this controller:

// courseguidecontroller.php public function viewaction(request $request) {     if (!$courseid = $request->get('id')) {         throw new notfoundhttpexception('no course id provided in ' . __method__);     }      $resource = $this->get('crmpicco.repository.course_guide_row')->createnew();     $form     = $this->getform($resource);      // ...  } 

my symfony formbuilder class:

// courseguiderowtype.php use sylius\bundle\resourcebundle\form\type\abstractresourcetype; use symfony\component\form\formbuilderinterface;  class courseguiderowtype extends abstractresourcetype {     /**      * {@inheritdoc}      */     public function buildform(formbuilderinterface $builder, array $options)     {         $builder             ->add('channel', 'crmpicco_channel_choice', array('data_class' => null))             ->add('name', 'text')             ->add('courses', 'text')         ;     }      /**      * @return string name      */     public function getname()     {         return 'crmpicco_course_guide_row';     } } 

i have tried data_class => null suggestion mentioned elsewhere, has no effect.

if pass through data_class this:

$form     = $this->getform($resource, array('data_class' => 'crmpicco\coursebundle\entity\courseguiderow')); 

i this:

neither property "translations" nor 1 of methods "gettranslations()", "translations()", "istranslations()", "hastranslations()", "__get()" exist , have public access in class "crmpicco\coursebundle\entity\courseguiderow".

why this? there translations attached courseguide entity not courseguiderow.

try add function in formtype:

public function configureoptions(optionsresolver $resolver) {     $resolver->setdefaults(array(         'data_class' => 'yourbundle\entity\yourentity',     )); } 

and don't forget specific use:

use symfony\component\optionsresolver\optionsresolver;

edit

in native symfony (with form component):

public function showaction() {     /.../     $entity = new yourentity();     $form = $this->createform('name_of_your_form_type', $entity);       # , response:      return $this->render('your_template.html.twig', ['form' => $form->createview()]); } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -