Rick Mason
Rick Mason

Reputation: 311

Symfony2 Catchable Fatal Error: Object of class Symfony\Component\Form\Form could not be converted to string

The stack trace seems to point to this in my entity

/**
 * @Assert\NotBlank()
 * @Assert\Type(type="numeric")
 * @Assert\GreaterThan(value=70)
 * @ORM\Column(type="decimal")
 */
public $start_weight;

The getter and setter for the start weight is as follows. Note that this was generated by the doctrine:generate:entities command.

/**
 * Set start_weight
 *
 * @param string $startWeight
 * @return User
 */
public function setStartWeight($startWeight)
{
    $this->start_weight = $startWeight;

    return $this;
}

/**
 * Get start_weight
 *
 * @return string 
 */
public function getStartWeight()
{
    return $this->start_weight;
}

And here is the entity manager in the indexAction

$email = $form->get('email')->getData();
            $user->setEmail($email);
            $first_name = $form->get('first_name')->getData();
            $user->setFirstname($first_name);
            $last_name = $form->get('last_name')->getData();
            $user->setLastname($last_name);
            $start_weight = $form->get('start_weight');
            $user->setStartWeight($start_weight);

            $em = $this->getDoctrine()->getManager();
            $em->persist($user);
            $em->flush();

when I run the code I get the Catchable Fatal Error Can't Convert to String. Through my searching here and elsewhere on internet land I know I need to add a __toString() method to my User Entity but I'm not sure exactly what to return.

Upvotes: 0

Views: 887

Answers (1)

Vadim Ashikhman
Vadim Ashikhman

Reputation: 10126

You forgot to call getData() method on the start_weight child form type.

Upvotes: 3

Related Questions