Symfony2 Catchable致命错误:类Symfony \ Component \ Form \ Form的对象无法转换为字符串

时间:2015-08-11 10:40:13

标签: symfony

堆栈跟踪似乎在我的实体中指向了这个

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

起始重量的吸气剂和设定器如下。请注意,这是由doctrine:generate:entities命令生成的。

/**
 * 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;
}

这是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();

当我运行代码时,我得到了Catchble Fatal Error无法转换为字符串。通过我在这里和互联网上的其他地方搜索我知道我需要向我的用户实体添加一个__toString()方法,但我不确定要返回什么。

1 个答案:

答案 0 :(得分:3)

您忘记在getData()子表单类型上调用start_weight方法。