首页 文章

Symfony 3 - AppBundle \ Entity \ User的查询缺少标识符ID

提问于
浏览
-1

我是开发新手 .

我想使用这个脚本: https://github.com/sebtouze/LoupGarou . 我很好地遵循了这些步骤,但是我收到了一个错误:

Doctrine \ ORM \ ORMException:在C:\ UwAmp \ www \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ ORMException.php第294行中,n / a处的AppBundle \ Entity \ User查询缺少标识符ID在Doctrine \中的Doctrine \ ORM \ ORME \ ORMException :: missingIdentifierField('AppBundle \ Entity \ User','id')在Doctrine \的C:\ UwAmp \ www \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ EntityManager.php第403行ORM \ EntityManager-> find('AppBundle \ Entity \ User',array('id'=> null),null,null)在C:\ UwAmp \ www \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ EntityRepository中.php第154行在Doctrine \ ORM \ EntityRepository-> find(null)中的C:\ UwAmp \ www \ src \ AppBundle \ Controller \ DefaultController.php第189行,位于AppBundle \ Controller \ DefaultController-> indexAction('public')in C:\ UwAmp \ www \ vendor \ symfony \ symfony \ src \ Symfony \ Component \ HttpKernel \ HttpKernel.php第135行在Symfony \ Component \ HttpKernel \ HttpKernel-> handleRaw(object(Request),'1')中的C: Symfony \ Component \ HttpKern的\ UwAmp \ www \ vendor \ symfony \ symfony \ src \ Symfony \ Component \ HttpKernel \ HttpKernel.php第57行el \ HttpKernel-> handle(object(Request),'1',true)位于Symfony的C:\ UwAmp \ www \ vendor \ symfony \ symfony \ src \ Symfony \ Component \ HttpKernel \ DependencyInjection \ ContainerAwareHttpKernel.php第67行在C:\ UwAmp \ www \ vendor \ symfony \ symfony \ src \ Symfony \ Component \ HttpKernel \ Kernel.php第183行中的Component \ HttpKernel \ DependencyInjection \ ContainerAwareHttpKernel-> handle(object(Request),'1',true) C:\ UwAmp \ www \ web \ app.php第28行中的Symfony \ Component \ HttpKernel \ Kernel-> handle(object(Request))

Error in picture

你能帮我吗 ?

提前致谢 .

3 回答

  • 0

    你有答案在你的帖子

    DefaultController.php line 189 您传递了null的变量 . 检查那里传递的变量,尤其是 id 我可以't say more because I don'看到你发布的代码只有错误 .

  • 0

    如上所述,您的错误在这里(DefaultController.php第189行):

    foreach($arraySynthesisMayorVotes as $vote)
    {
        $vote = $userRepository->find($vote['id']);
    }
    

    你正在经历一个foreach并一遍又一遍地覆盖$ vote . 它也是你和foreach一样的变量 .

  • 0

    我认为这个代码块是罪魁祸首 . 我无法理解这个代码块 . 我认为您需要更改或删除它

    $userRepository = $em->getRepository('AppBundle:User');
    foreach($arraySynthesisMayorVotes as $vote)
    {
            $vote = $userRepository->find($vote['id']);
    }
    foreach($arraySynthesisVillageVotes as $vote)
    {
            $vote = $userRepository->find($vote['id']);
    }
    

    如果您想计算总票数,可以使用 count($arraySynthesisVillageVotes) . 但这取决于您的业务逻辑

相关问题