【问题标题】:EasyAdminBundle 3:collection field with entityEasyAdminBundle 3:带有实体的集合字段
【发布时间】:2021-03-04 09:38:52
【问题描述】:

我有两个班级:

class Product {
     /**
     * @ORM\OneToMany(targetEntity=Keyword::class, mappedBy="product")
     */
    private $keywords;
}

class Keyword {
     /**
     * @ORM\Column(type="string", length=255)
     */
    private $description;

    /**
     * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="keywords")
     */
    private $product;
}

在我定义的产品的 CRUD 控制器中:

public function configureFields(string $pageName): iterable
{
     yield CollectionField::new('keywords');
}

它正确显示了所有关键字,但是当我尝试保存它时出现错误:

“App\Entity\Keyword”、“字符串”类型的预期参数在属性路径“关键字”处给出。

是否有可能将这样的连接显示为集合?这样管理关键字会容易得多。

【问题讨论】:

    标签: php symfony symfony5 easyadmin


    【解决方案1】:

    你需要使用

    yield AssociationField::new('keywords');
    

    而不是

    yield CollectionField::new('keywords');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多