symfony 2 form表单和doctrine 问题求助
我要实现自分类功能,现在的form表单中有一个parent项,以及isRoot项,产品分类类中这样定义:
/**
* @var string $parent
* @ORM\ManyToOne(targetEntity="ProductCategory")
* @ORM\JoinColumn(name="product_category_id", referencedColumnName="id")
*/
private $parent;
提取表单内容并插入数据库:
$entity = new ProductCategory();
$request = $this->getRequest();
$form = $this->createForm(new ProductCategoryType(), $entity);
$form->bindRequest($request);
//如果多选按钮(checkbox) isRoot选中,将parent置为NONE
if($entity->getIsRoot()){
$entity ->setParent('NONE');
}
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('product_category_show', array('id' => $entity->getId())));
经过验证,在$em->flush();执行时出现错误:
Warning: spl_object_hash() expects parameter 1 to be object, string given in /.../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php line 1073
请问下这是什么问题,该如何解决呢?先谢了^_^