gpt4 book ai didi

php - Doctrine 多对一映射问题

转载 作者:可可西里 更新时间:2023-10-31 22:18:06 25 4
gpt4 key购买 nike

尝试创建外键映射(即将类别映射到产品)时,我在“创建产品”页面中收到以下错误:

A "__toString()" method was not found on the objects of type "CJ\BusinessBundle\Entity\Category" passed to the choice field. To read a custom getter instead, set the option "property" to the desired property path.

最佳答案

您需要将 __toString() 方法添加到您的类别实体。例如:

public function __toString()
{
return $this->name;
}

PHP 魔术方法 __toString() 用于呈现对象的文本表示。在这种情况下,在相关实体的表单中选择类别时将使用类别名称。

关于php - Doctrine 多对一映射问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15497348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com