database - Symfony2 : Database and Entity settings: Neither property . .. 类中也没有方法 ... 也没有方法 ... 存在于类中

标签 database symfony entity

我有一个连接到数据库的 Symfony2 项目。对于每个表,我都有一个实体。

现在,我正在尝试使用 ManyToOne 将一个实体与另一个实体连接起来。

问题是:

我有两个实体:用户和工作场所。

在用户实体中,我有:

 /**
 * @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;
}

有了这个,我得到了一个异常(exception):

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'))

在您的表单类型中。

关于database - Symfony2 : Database and Entity settings: Neither property . .. 类中也没有方法 ... 也没有方法 ... 存在于类中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853731/

相关文章:

mysql - 在 WHERE 语句中添加和比较列

mysql - 检测同一查询中数据库和表是否存在

MySQL : weekly and monthly average

php - Symfony 3.4 没有要处理错误的元数据类

validation - Symfony2 : How to validate an entity by taking into account the currently logged in user?

数据库设计?

javascript - Ajax with twig,它是如何工作的?

entity - 如何验证实体内的电子邮件?

forms - 从现有实体 Symfony4 生成表单

php - Symfony2 : Entity created but, 给的类不存在