Database Symfony2:数据库和实体设置:都不是属性。。。也不是方法…也不是方法。。。存在于课堂上
我有一个Symfony2项目连接到数据库。对于每个表,我都有一个实体 现在,我正在尝试使用manytone将一个实体与另一个实体连接起来 问题是: 我有两个实体:用户和工作场所 在用户实体中,我有:Database Symfony2:数据库和实体设置:都不是属性。。。也不是方法…也不是方法。。。存在于课堂上,database,symfony,entity,Database,Symfony,Entity,我有一个Symfony2项目连接到数据库。对于每个表,我都有一个实体 现在,我正在尝试使用manytone将一个实体与另一个实体连接起来 问题是: 我有两个实体:用户和工作场所 在用户实体中,我有: /** * @ORM\ManyToOne(targetEntity="Workplace") * @ORM\JoinColumn(name="workplace", referencedColumnName="place") **/ protected $workplace; /** *
/**
* @ORM\ManyToOne(targetEntity="Workplace")
* @ORM\JoinColumn(name="workplace", referencedColumnName="place")
**/
protected $workplace;
/**
* Set workplace
*
* @param integer $workplace
*/
public function setWorkplace($workplace)
{
$this->workplace = $workplace;
}
/**
* Get workplace
*
* @return integer
*/
public function getWorkplace()
{
return $this->workplace;
}
在工作场所实体中,我有:
/**
* @ORM\Column(type="text")
*/
protected $place;
/**
* Set place
*
* @param text $place
*/
public function setPlace($place)
{
$this->place = $place;
}
/**
* Get place
*
* @return text
*/
public function getPlace()
{
return $this->place;
}
因此,我得到了一个例外:
Neither property "workplace" nor method "getWorkplace()" nor method "isWorkplace()" exists in class "SciForum\Version2Bundle\Entity\Workplace"
如何解决这一问题。非常感谢。试试这个
->add('place','entity', array('class'=>'yourBundle:WorkPlace',
'property'=>'place'))
在您的表单类型中。@Asish AP是正确的,但缺少解释 在formBuilder中,如果两个实体之间存在关系,则必须在表单类型中指定正确的实体
->add(
'place',
'entity',
array(
'class'=>'yourBundle:WorkPlace', //Link your entity
'property'=>'place' //Specify the property name in the entity
))
如果在formBuilder中指定不存在的属性,则会出现以下错误:
Neither property "workplace" nor method "getWorkplace()" nor method "isWorkplace()" exists in class "SciForum\Version2Bundle\Entity\Workplace"
这就是你错误的原因和解决方案的解释
我认为您遗漏了每个实体中的setter和getter函数。通常情况下,我会编辑问题并提供更多详细信息。您能否发送控制器代码和工作区实体?如何发送?要在问题中发帖吗?哦,我找到了解决方案,在我的控制器中填充表单时,我使用了'property'=>'workplace'而不是'property'=>'workplace'。