Reputation: 65
I have a problem when I'm trying to create an EntityType field in my Symfony2 form type.
This is the piece of code from the official EntityType reference in Symfony2 manual:
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
...
$builder->add('users', EntityType::class, array(
'class' => 'AppBundle:User',
'choice_label' => 'username',
));
Going back to the browser I'm getting the Could not load type "Symfony\Bridge\Doctrine\Form\Type\EntityType"
error.
The EntityType class exist in the given namespespace.
Do I need to get some aditional extensions for this field type?
Upvotes: 1
Views: 11128
Reputation: 2106
The EntityType class is not located in the common Type classes folder (Symfony\Component\Form\Extension\Core\Type\
), but in Symfony\Bridge\Doctrine\Form\Type\
So if you are using Symfony 3 or Symfony 2.8 and the EntityType::class
syntax, you must put
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
Upvotes: 8
Reputation: 3573
What version of Symfony are you using?
This FooBarType::class
thing is new in Symfony 2.8 and 3.x, older versions do not support it. Try replacing EntityType::class
by 'entity'
and see if that works. When you upgrade to Symfony 2.8 you may use the FQCN and from 3.x this will be the only option.
Upvotes: 10