Php 如何删除实体关系(Symfony 4)?

Php 如何删除实体关系(Symfony 4)?,php,symfony,doctrine,entity,symfony4,Php,Symfony,Doctrine,Entity,Symfony4,我的表格字段: id name 1 cat 2 dog 3 frog 我的桌子产品组 id name 1 animals 2 food 3 colors fields_1 productgroup_1 1 1 2 1 3 2 我的表字段\u产品组 id name 1 animals 2 food 3 colors fields_1 productgroup_1 1 1 2

我的表格字段:

id  name
1   cat
2   dog 
3   frog
我的桌子产品组

id  name
1   animals
2   food 
3   colors
fields_1  productgroup_1
1         1
2         1
3         2
我的表字段\u产品组

id  name
1   animals
2   food 
3   colors
fields_1  productgroup_1
1         1
2         1
3         2
我现在想做的是去掉青蛙和颜色的关系

我的控制器:

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;
}
但我得到了错误信息:

语法错误,意外的“return”T\u返回


如果答案中的代码与您使用的代码完全相同,则以下代码段中存在语法错误:

public function removeProductgroup(Productgroup $productgroup)
{
    $this->productgroup->removeElement($productgroup) // missing semicolon here

    return $this;
}
必须用分号结束语句行。解释器看到关键字return并抛出语法错误。对于PHP,空格没有区别,因此它将代码解释为:

$this->productgroup->removeElement($productgroup) return $this;

我没想到,这是一个如此简单的错误……我没有否决你的问题。只有被否决的人才知道真正的原因。我想这是因为语法错误,通过彻底的代码内省,很容易找到语法错误。我很高兴它现在起作用了。