我的表字段:
id name
1 cat
2 dog
3 frog
我的表productgroup
id name
1 animals
2 food
3 colors
我的表fields_productgroup
fields_1 productgroup_1
1 1
2 1
3 2
我想现在要做的是去掉frog
的关系colors
。
我的控制器:
public function remove($entity, $id, $relation, $relation_id, Request $request)
{
$obj = $this->getDoctrine()->getRepository(fields::class)->findOneBy(['id' => $id]);
$entity_id = $obj->getId();
$enity_reference = $entityManager->getReference(fields::class, $entity_id);
$relation_reference = $entityManager->getReference(productgroup::class, $relation_id);
$func = 'removeProductgroup';
$enity_reference->$func($relation_reference);
$entityManager->persist($enity_reference);
$entityManager->persist($relation_reference);
$entityManager->flush();
$response = new Response();
$response->send();
return $response;
}
这是在我的领域实体的功能:
public function removeProductgroup(Productgroup $productgroup)
{
$this->productgroup->removeElement($productgroup)
return $this;
}
但我得到的错误信息:
语法错误,意想不到的“回归”(T_RETURN)
如果你的答案代码正是你使用的代码,那么你必须在下面的代码片段语法错误:
public function removeProductgroup(Productgroup $productgroup)
{
$this->productgroup->removeElement($productgroup) // missing semicolon here
return $this;
}
这显然应:
public function removeProductgroup(Productgroup $productgroup)
{
$this->productgroup->removeElement($productgroup);
return $this;
}
你必须完成一个语句行用分号。解释器看到关键字return
并引发语法错误。 PHP的空白没有什么区别,所以它解释代码:
$this->productgroup->removeElement($productgroup) return $this;