我正在尝试使用服务在表中创建行。但是它表示在非对象上调用成员函数setFirstname(),这是行:
$this->idm->setPersno($science->getPersno());
我在谷歌搜索了几个小时,无法找到问题的解决方案。有人能帮助我吗?
$scienceList = $this->em->getRepository('MyBundle:MyTable1')->findAll();
foreach ($scienceList as $science)
{
$idm = new Users();
$this->idm = $this->em->getRepository('MyBundle:MyOtherTable')->find($science->getPersno());
if($this->idm == null)
{
$this->idm->setPersno($science->getPersno());
$this->idm->setFirstname($science->getFirstname());
$this->idm->setLastname($science->getLastname());
$this->em->persist($idm);
}
}
$this->em->flush();
答案 0 :(得分:0)
$this->idm = $this->em->getRepository('MyBundle:MyOtherTable')->find($science->getPersno());
if($this->idm == null)
{
$this->idm = new Users();
$this->idm->setPersno($science->getPersno());
$this->idm->setFirstname($science->getFirstname());
$this->idm->setLastname($science->getLastname());
$this->em->persist($this->idm);
}