0
votes

I am a novice in development.

I want use this script : https://github.com/sebtouze/LoupGarou. I followed the steps well, but I get an error:

Doctrine\ORM\ORMException: The identifier id is missing for a query of AppBundle\Entity\User at n/a in C:\UwAmp\www\vendor\doctrine\orm\lib\Doctrine\ORM\ORMException.php line 294

at Doctrine\ORM\ORMException::missingIdentifierField('AppBundle\Entity\User', 'id') in C:\UwAmp\www\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php line 403

at Doctrine\ORM\EntityManager->find('AppBundle\Entity\User', array('id' => null), null, null) in C:\UwAmp\www\vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php line 154

at Doctrine\ORM\EntityRepository->find(null) in C:\UwAmp\www\src\AppBundle\Controller\DefaultController.php line 189

at AppBundle\Controller\DefaultController->indexAction('public') in C:\UwAmp\www\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 135

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') in C:\UwAmp\www\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 57

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) in C:\UwAmp\www\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php line 67

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true) in C:\UwAmp\www\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php line 183

at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) in C:\UwAmp\www\web\app.php line 28

Error in picture

Can you help me please ?

Thank's in advance.

4
You must test the contents of your variables. Here, a variable that should contain an id is in fact null.Lapixel

4 Answers

0
votes

You have answer in your post

DefaultController.php line 189 you passed variable that is null. Check the variables that are passed there especially id I can't say more because I don't see the code you posted only error.

0
votes

As mentioned your error is here (DefaultController.php line 189):

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

You're going through a foreach and overwriting $vote over and over. It's also the same variable you're passing into with your foreach.

0
votes

I think this code block is culprit. I couldnt make any sense of this code block. I think you need to change it or remove it

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

If you wanted to count total votes, you can use count($arraySynthesisVillageVotes). But it depends upon your business logic

0
votes

An entity is not an array and cannot be queried as such. It is an object.

At line(s) 189 (and 193), instead of:

$vote = $userRepository->find($vote['id']);

try:

$vote = $userRepository->find($vote->getId());