我是Doctrine的新手,对persisten&脸红即使我不调用flush,实体也会自动保存到数据库中。我正在使用Slim框架与条令2的api。
public function addSource($request, $response, $args) {
$apiData = new 'App'Entity'Source();
$apiData->setSourceName('dasds');
$apiData->setSourceDesc('jasgd<sg');
$now = new 'DateTime("now");
$apiData->setCreated($now);
$apiData->setModified($now);
$this->sourceResource->entityManager->persist($apiData);
//$this->entityManager->flush();
echo 'here';exit;
return $response->withJSON($apiData);
}
在上面的代码中,如果我把die放在代码后面,那么它不会保存到数据库中,但当我让响应返回时,它会自动保存。
flush()
在其他地方被调用-可能在中间件中,也可能在index.php的末尾。