开发者

ErrorException: Catchable Fatal Error: Object of class could not be converted to string - Caused by dropdown menu but why?

I have the following code, which retrieves the page slugs from the database which are needed to then create a related sub page:

        $builder->add('subtocontentoptions', 'entity', array(
            'class' => 'ShoutAdminBundle:Content',
            'property' => 'slug',
            'query_builder' => function($repository) { 
                return $repository->createQueryBuilder('p')
                ->where('p.mainpage = :main')
                ->setParameter('main', '1')
                ->orderBy('p.created', 'ASC');
            }
        ));

The code works, as it displays a drop down menu of all the parent pages I have. However, when I go to save the data to the database, I am given the following error:

ErrorException: Catchable Fatal Error: Object of class Shout\AdminBundle\Entity\Content could not be converted to string in C:\wamp\www\vendor\doctrine-dbal\lib\Doctrine\DBAL\Statement.php line 131

I have checked the contents of the Content entity file, and here is the variable being declared:

/**
 开发者_高级运维* @var integer $subtocontentoptions
 *
 * @ORM\Column(name="SubToContentOptions", type="integer", nullable=false)
 */
private $subtocontentoptions;

And lower down the Content entity file:

/**
 * Set subtocontentoptions
 *
 * @param integer $subtocontentoptions
 */
public function setSubtocontentoptions($subtocontentoptions)
{
    $this->subtocontentoptions = $subtocontentoptions;
}

/**
 * Get subtocontentoptions
 *
 * @return integer 
 */
public function getSubtocontentoptions()
{
    return $this->subtocontentoptions;
}

The rest of the code does work, once this drop down has been taken out. I'm not sure why the drop down is causing this error?

Thanks


Was having the same issue with a sf2/doctrine2 project, implementing the __toString method resolved this issue for me :

public function __toString()
{
    return strval($this->id);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜