I tried to call the repository of my entity Category
in the class form of my entity BonCommande
, but this error ocuured:
Notice:
FormComponent is an independent component and it doesn't provide any entityManager to use. You have to inject it or pass it by $options
if you want to use it..
In your case it would be correct if you directly pass it to the type's __construct
or pass by $options
array or declare your type as a service and inject entity manager to it:
class BonCommandeType extends AbstractType
{
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
...
}
or
$this->createForm(TYPE, DATA, ['em' => $em]);
From your code I assume you are missing this:
//Somewhere at the begging of your BonCommandeType
protected $em;
...
public function __construct(EntityManager $em)
{
$this->em = $em;
}
Keep in mind that when you create a new form object you should use smth like :
BonCommandeType($this->getDoctrine()->getManager()) // if inside a controller