【问题标题】:Catchable Fatal Error: Object of class AppBundle\Entity\Job could not be converted to string可捕获的致命错误:AppBundle\Entity\Job 类的对象无法转换为字符串
【发布时间】:2017-12-05 19:25:03
【问题描述】:

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

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

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

【问题讨论】:

    标签: php symfony symfony2-easyadmin


    【解决方案1】:

    将此方法添加到您的 Job 类中

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

    【讨论】:

    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 2016-01-18
    • 2016-03-09
    • 2017-10-17
    • 2015-03-08
    • 2013-08-07
    • 2014-06-04
    • 2018-03-12
    相关资源
    最近更新 更多