I have this code in my form builder
->add('user', 'entity', array(
'class' => 'Acme\Entity\User',
'query_builder' => function(EntityRepository $er) use ($options) {
return $er->createQueryBuilder('u')
->where('u.id = :id')
->setParameter('id',$options['my'])
->orderBy('u.name', 'ASC');},))
When I echo $options['my'] I get output as 1 inside the builder.
Now when I submit the form, I get NULL as the User object.
But if I use ->setParameter('id',1) then it works fine.
Now if i use this
$options['test'] = 1 inside the build form and use
->setParameter('id',$options['test']) then it also work fine.
But ->setParameter(‘id’,$options[‘my’]) is not working directly. It is echoing fine as 1 in the form , so value is in that variable.
What should I do?
It is a common error of type.
1is a string in the first case and a int in the second case. Try if this works:Your debug is really good though, but it is better to use
var_dumprather thanecho. You can also compare the types withgettype().Compare
var_dump($options['my'])withvar_dump($options[test']).Compare
gettype($options['my'])withgettype($options['test']).