简体   繁体   中英

Doctrine mapping field error

i have a Entity with 2 attributs _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;
  }
}

Doctrine can't call set_obcId() , get_obcId(), it return 'neither the property nor one of the methods', i write also an __set and __get , but it does'n't work.

If you want to use the getters/setters that way, try renaming your variables:

private $obcId;
private $_obcId;

However, I recommend not using 2 column names that are so similar, and not using an underscore at the start of your column name (and consequently not using it in the variable name either).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM