如何初始化构造函数类中的ID值并获取doctrine,symfony2中的最后一个ID自动增量?

时间:2014-05-14 09:03:35

标签: symfony doctrine construct

我有一个带字段ID自动增量的类

班普鲁巴{

/**
 * @var integer $id
 *
 * @ORM\Column(name="`id`", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

但是当我尝试这个时:

public function __construct()
    {


      $this->entorno = new Entorno('MSU',$this->id);

    }

this-> id未初始化为1且为NULL

我想要这个:

如果是第一个新的Prueba()或doctrine prueba是空的

 $this->id = 1

其他

$this->id=get the last ID from table Prueba in doctrine.

我该怎么做?

1 个答案:

答案 0 :(得分:0)

对不起,我忘了将它包含在我的Entorno类中:* @ORM \ JoinColumn(name =“prueba_id”,referencedColumnName =“id”)