如何在构造函数类中初始化一个ID值,并在条令symfony2中获得las ID自动增量?

如何在构造函数类中初始化一个ID值,并在条令symfony2中获得las ID自动增量?,symfony,doctrine,construct,Symfony,Doctrine,Construct,我有一个字段ID为autoincrement的类 普鲁巴类{ /** * @var integer $id * * @ORM\Column(name="`id`", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; 但当我尝试这个: public function __construct() { $this->entorno = new

我有一个字段ID为autoincrement的类

普鲁巴类{

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

    }
此->id未初始化为1且为空

我想要这个:

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

 $this->id = 1
否则


我该怎么办?

对不起,我忘了在我的课程中包括这个:@ORM\JoinColumn(name=“prueba\u id”,referencedColumnName=“id”)

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