如何在 symfony 3 中将对象数组转换为字符串? [英] How to convert an array of objects as string in symfony 3?

查看:56
本文介绍了如何在 symfony 3 中将对象数组转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 b/w 2 实体(产品和报价)中实现多对多关系时出现以下错误:

I'm getting the following error while implementing the many-to-many relationship in b/w 2 entities(Product & Offer):

可捕获的致命错误:FoodBundle\Entity\Product 类的对象可以不会被转换成字符串

Catchable Fatal Error: Object of class FoodBundle\Entity\Product could not be converted to string

产品实体与要约实体的关系.我的目标是利用多对多关系的产品报价.

Where Product entity is in relation with the Offer entity. My aim here was to avail offers to products in many-to-many relationship.

这段代码正在创建它,正如我从错误中猜测的那样.

This piece of code is creating it as I guess from the error.

class Offer
{
    public function addProduct(\FoodBundle\Entity\Product $product)
    {
        $this->product[] = $product;
        return $this;
    }
}

请帮我解决这个问题.

推荐答案

当您自动创建 CRUD 时,此问题很常见.

This problem is common when you've created the CRUD automatically.

问题是你需要从一个

发送“验证码”获取 | 15天全站免登陆