I have two tables one is users like this
id _ username _ firstname _ lastname
and the other one is users_test
id _ user_id _ name
I'm trying in Symfony Form (UserTestType) to make a Custom Query to get the id from the first Entitiy (UsersType) and insert the id as a Value. my code is like this:
$builder->add('user_id', EntityType::class, array(
'class' => 'UserBundle:Users',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.id', 'ASC');
},
'choice_label' => 'firstname',
'choice_value' => 'id',
));
when i reload the page it says: Could not load type "Symfony\Component\Form\Extension\Core\Type\EntityType"
note: I'v used Symfony\Component\Form\Extension\Core\Type\EntityType;
I hope someone could help me to find my Problem.
I just tried it out and you probally copy&paste the TextType from user/first/lastname and just changed the last part of the Namespace, which lead you to the namespace where TextType and many other Types are lying. (I did the exact same mistake and lost 2 minutes of my life)
For EntityType and DoctrineType, you need to use following namespace:
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
Also if you didn't do it (I know you wrote you use it, but just in case), you should also use your User Entity Class like:
use UserBundle\Entity\Users;
(or using the Singular form User, which I would recommend so you have no struggling with singular/plural)
I also remember reading somewhere that it is recommended to use the FQCN via ::class so you could think changing:
'class' => 'UserBundle:Users',
to
'class' => Users::class,