Reputation: 441
I have a form class as a (service) and I use entity type
for select an article.
In Symfony 2 this works:
$builder
->add('article', EntityType::class,
array(
'em' => $this->em,
'class' => 'MyBundle\Entity\Article',
'query_builder' => function ($em) {
return $em->createQueryBuilder('a')
->where('a.active = 1');
},
'choice_label' => 'name')
)
But in Symfony3 I got error:
Neither the property "article" nor one of the methods ...
My problem is that Article hasn't property article
. When I rename article to name
->add('name', ...`
How can I pass Article Entity to Form please?
Upvotes: 0
Views: 1549
Reputation: 1899
In Symfony 3, you need to use Fully Qualified Class Name, so instead of:
'class' => 'MyBundle\Entity\Article',
you need to use:
'class' => \MyBundle\Entity\Article::class,
Read more about this in the book: http://symfony.com/doc/current/book/forms.html#building-the-form And maybe you want to check all other things that you need to change when upgrading from Symfony 2 to Symfony 3: https://github.com/symfony/symfony/blob/master/UPGRADE-3.0.md
Upvotes: 2