Symfony Error when loading a Profile Form -


i'm getting error when trying load edit form profile entity.

the form's view data expected instance of class appbundle\entity\profile, a(n) array. can avoid error setting "data_class" option null or adding view transformer transforms a(n) array instance of appbundle\entity\profile. 

i wondering if knows how fit this. i'm using profile controller , user , profile have onetoone relationship each other.

here code profile controller loads form

/**  * @route("/profile/edit", name="profile_edit")  */ public function editaction(request $request) {      $em = $this->getdoctrine()->getmanager();     $profilerepository = $em->getrepository(profile::class);      $user = $this->getuser();      $profile = $profilerepository->getprofilebyuserid($user->getid());      $form = $this->createform(profiletype::class, $profile);      $form->handlerequest($request);      if( $form_.issubmitted() && $form->isvalid()) {          $firstname = $form->get('firstname')->getdata();         $lastname = $form->get('lastname')->getdata();          $description = $form->get('description')->getdata();          $profile->setfirstname($firstname);         $profile->setlastname($lastname);         $profile->setdescription($description);          $em->persist($profile);         $em->flush();          $this->addflash('flash-profileeditted', 'you\'ve updated profile.');         $this->redirecttoroute('profile_page');     }      return $this->render('profile/edit.html.twig', ['form' => createform(), 'profile' => $profile]); } 

and here profiletype::class

public function buildform(formbuilderinterface $builder, array $options) {     $builder     ->add('firstname', texttype::class, [ 'label' => 'firstname', 'attr' => ['class' => 'form-control']])     ->add('lastname', texttype::class, ['label' => 'lastname', 'attr' => ['class' => 'form-control']])     ->add('description', textareatype::class, ['label' => 'in own words', 'attr' => ['class' => 'form-control']])     ->add('user')     ->add('submit', submittype::class, ['label' => 'edit profile', 'attr' => ['class' => 'btn btn-info']]); }  /**  * {@inheritdoc}  */ public function configureoptions(optionsresolver $resolver) {     $resolver->setdefaults(array(         'data_class' => 'appbundle\entity\profile'     )); }  /**  * {@inheritdoc}  */ public function getblockprefix() {     return 'appbundle_profile'; } 

not sure else include here, ok , solution can found within code.

i should point out using fosuserbundle.

thanks in advance,

ok. found out happening. using profile repository find user id, returning array. had use code:

  $profile = $profilerepository->findonebyuser($user->getid()); 

this returns object appbundle\entity\profile object can used populate form.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -