学说映射字段错误


Doctrine mapping field error

我有一个具有 2 个属性的实体 _obc_id, obc_id

class myEntity {
  ...
  /**
   * @ORM'Column(name="obc_id", type="integer", nullable=false)
   */
  private $obc_id;
  /**
   * @ORM'Column(name="_obc_id", type="integer", nullable=false)
   */
  private $_obc_id;
  public function get_obcId()
  {
    return $this->_obc_id;
  }
  public function getObcId()
  {
    return $this->obc_id;
  }
  public function set_obcId($value);
  {
     $this->_obc_id = $value;
     return $this;
  }
  public function setObcId($value);
  {
     $this->obc_id = $value;
     return $this;
  }
}

教义不能调用set_obcId() , get_obcId(),它返回"既不是属性也不是方法之一",我也写了一个__set和__get,但它不起作用。

如果你想以这种方式使用 getters/setter,请尝试重命名你的变量:

private $obcId;
private $_obcId;

但是,我建议不要使用如此相似的 2 列名,也不要在列名的开头使用下划线(因此也不要在变量名称中使用它)。