-3

谁能帮我解决这个问题?我不知道为什么,但我得到了这个例外:

可捕获的致命错误:AppBundle\Entity\Job 类的对象无法转换为字符串

我的实体类别:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Category
 *
 * @ORM\Table(name="category")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository")
 */
class Category
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="label", type="string", length=255)
     */
    private $label;


    /**
    * @var string
     *@ORM\ManyToMany(targetEntity="Job", mappedBy="categories", cascade={"persist", "merge"})
    */
    private $jobs ; 


    /**
     * Constructor
     */
    public function __construct()
    {
        $this->jobs = new \Doctrine\Common\Collections\ArrayCollection();
    }



    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set label
     *
     * @param string $label
     *
     * @return Category
     */
    public function setLabel($label)
    {
        $this->label = $label;

        return $this;
    }

    /**
     * Get label
     *
     * @return string
     */
    public function getLabel()
    {
        return $this->label;
    }
    /**
     * Add job
     *
     * @param \AppBundle\Entity\Job $job
     *
     * @return Category
     */
    public function addJob(\AppBundle\Entity\Job $job)
    {
        $this->jobs[] = $job;

        return $this;
    }

    /**
     * Remove job
     *
     * @param \AppBundle\Entity\Job $job
     */
    public function removeJob(\AppBundle\Entity\Job $job)
    {
        $this->jobs->removeElement($job);
    }

    /**
     * Get jobs
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getJobs()
    {
        return $this->jobs;
    }

}

实体配置(easyadmin),我选择自定义一些字段:

easy_admin:

    design:

    entities:
        Category:
            class: AppBundle\Entity\Category

屏幕截图是否解释了该错误或它的确切含义?

在此处输入图像描述

4

1 回答 1

3

将此方法添加到您的 Job 类

public function __toString() {
    return "some string representation of your object"
}
于 2017-12-05T19:26:06.993 回答