我插入多行,我想在doctrine zend框架3中同时检索所有行id。
foreach($rippleids as $rid)
{
$scheduleItem=[];
$scheduleId=[];
$rippleid = StaticFilter::execute($rid, 'StringTrim');
if (empty($rippleid)) {
continue;
}
//return;
$schedule= new Schedule();
$id= uniqid();
$schedule->setScheduleUId($id);
$ripple=$this->entityManager->getRepository(Ripple::class)->findOneBy(['id'=>$rippleid,'status'=>[1,2]]);
$schedule->setRipple($ripple);
$template=$this->entityManager->getRepository(Template::class)->findOneBy(['Id'=>$data[2]]);
$schedule->setTemplate($template);
$schedule->setStatus(1);
$schedule->setScheduleName($data[1]);
$schedule->setRecordingEnable($data[5]);
$schedule->setStartDateTime($startDateTime);
$schedule->setEndDateTime( $endDateTime);
$schedule->setScheduleStatus(0);
$schedule->setModifiedDate(date("Y-m-d H:i:s"));
$schedule->setSyncStatus(0);
$this->entityManager->persist($schedule);
$this->entityManager->persist($schedule);
$scheduleId=$schedule->getScheduleId();
此代码只返回一个Id,但我想检索所有插入id的行
这是一个简单的问题,你需要在$ scheduleId上添加[]。
看起来像这样:$ scheduleId [] = $ schedule-> getScheduleId();