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

时间:2017-12-05 19:25:04

标签: php symfony symfony2-easyadmin

任何人都可以帮我解决这个问题吗?我不知道为什么,但我得到了这个例外:

  

捕获致命错误:类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

屏幕截图是否解释了这个错误或它究竟意味着什么?

enter image description here

1 个答案:

答案 0 :(得分:2)

将此方法添加到您的Job类

public function __toString() {
    return "some string representation of your object"
}