Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 原则2-如何在PostPersist中获取最后一个插入ID的ID?_Php_Doctrine Orm_Lastinsertid - Fatal编程技术网

Php 原则2-如何在PostPersist中获取最后一个插入ID的ID?

Php 原则2-如何在PostPersist中获取最后一个插入ID的ID?,php,doctrine-orm,lastinsertid,Php,Doctrine Orm,Lastinsertid,标题解释了一切。我在实体中有一个lifecyclecallback函数。我想从PostPersist事件而不是实体中获取最后插入的id。举个例子,我不想这样做 $newSeating = new Seat(); $newSeating->setTitle("Something"); $this->_em->persist($newSeating); $this->_em->flush(); $newSeating->getId(); 在文档中是这样写的 po

标题解释了一切。我在实体中有一个lifecyclecallback函数。我想从PostPersist事件而不是实体中获取最后插入的id。举个例子,我不想这样做

$newSeating = new Seat();
$newSeating->setTitle("Something");
$this->_em->persist($newSeating);
$this->_em->flush();
$newSeating->getId();
在文档中是这样写的

postPersist-postPersist事件 在实体之后的实体中发生 已经变得持久。会的 在数据库插入后调用 操作。生成的主键 值可在中找到 后期事件

那么如何在postPersist中获取主键值呢? (我正在使用Mappedsuperclass,postpersist函数位于Mappedsuperclass中,因此它可用于扩展Mappedsuperclass的每个实体)
谢谢。

它抛出了一个错误,postpersist需要1个参数,但给定了0。您使用的是哪一个Doctrine 2版本?能否显示注册了
postpersist
事件处理程序的相关代码?
...
public function postPersist(\Doctrine\ORM\Event\LifecycleEventArgs $e) {
    $newSeating = $e->getEntity();
    $id         = $newSeating->getId();
}
...