Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Using a Custom Query for the Entities in Doctrine - Symfony Form

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.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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,

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda