Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda