Warning: spl_object_hash() expects parameter 1 to be object, with Message

本小妞迷上赌 提交于 2019-12-02 04:36:51

Ok found answer

what i was doing was wrong i was doing this

if ($request->isPost()) {
    $subject = new Subject();
    $form->setInputFilter($subject->getInputFilter());
    if ($form->isValid()) {
        $subject->populate($form->getData());
        $this->getEntityManager()->persist($subject);
        $this->getEntityManager()->flush();
        return $this->redirect()->toRoute('subject');
    }
}

Instead i had to first find the Relevant entity like this

 if ($request->isPost()) {
        $subject = new Subject();

//following is the line  i was looking for
        $user = $this->getEntityManager()->getRepository('Subject\Entity\User')->find(array('id'=>$userid));
        $form->setInputFilter($subject->getInputFilter());
        if ($form->isValid()) {
            //$user->add
            //$subject->setUser($user);
            $subject->populate($form->getData());
            $subject->setUser($user);
            $this->getEntityManager()->persist($subject);
            $this->getEntityManager()->flush();
            return $this->redirect()->toRoute('subject');
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!