簡體   English   中英

教義映射字段錯誤

[英]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,但是它不起作用。

如果要以這種方式使用getter / setter,請嘗試重命名變量:

private $obcId;
private $_obcId;

但是,我建議不要使用兩個如此相似的列名,也不要在列名的開頭使用下划線(因此也不要在變量名中使用下划線)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM