Reputation: 31
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
Can you help me please ?
Thank's in advance.
Upvotes: 1
Views: 16145
Reputation: 131
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());
Upvotes: 2
Reputation: 792
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
Upvotes: 0
Reputation: 38
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.
Upvotes: 0
Reputation: 20286
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.
Upvotes: 1