Symfony2: How call the repository of an entity in the FormType

后端 未结 2 652
走了就别回头了
走了就别回头了 2021-01-26 06:52

I tried to call the repository of my entity Category in the class form of my entity BonCommande, but this error ocuured:

Notice:

2条回答
  •  有刺的猬
    2021-01-26 07:29

    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
    

提交回复
热议问题