我有下面的代码,它检索来自这是需要再创建一个相关的子页面数据库中的网页蛞蝓:ErrorException:可捕获的致命错误:类的对象无法转换为字符串 - 由下拉菜单引起的,但为什么?
$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');
}
));
代码的工作,因为它会显示一个下拉所有父页面菜单我有。然而,当我去保存数据到数据库中,我提示以下错误:
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
我已经检查了内容的实体文件的内容,并在这里被声明的变量:
/**
* @var integer $subtocontentoptions
*
* @ORM\Column(name="SubToContentOptions", type="integer", nullable=false)
*/
private $subtocontentoptions;
,并降低下来的内容实体文件:
/**
* Set subtocontentoptions
*
* @param integer $subtocontentoptions
*/
public function setSubtocontentoptions($subtocontentoptions)
{
$this->subtocontentoptions = $subtocontentoptions;
}
/**
* Get subtocontentoptions
*
* @return integer
*/
public function getSubtocontentoptions()
{
return $this->subtocontentoptions;
}
的代码的其余部分没有工作,一旦这个下拉已经被取出。我不确定为什么下拉导致这个错误?
感谢
什么的下拉期权的价值?它是根据表中的int值吗? – Tjorriemorrie
是的,它使用表的Int(ID)字段。我试图改变这个,所以它使用了不同的值。 – mickburkejnr
试着让'subtocontentoptions'受到保护而不是私人的 – Reuven