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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With